From 80274e3825fe8925782311350bde4d2bdd6f386c Mon Sep 17 00:00:00 2001 From: Will Ezell Date: Thu, 1 Feb 2024 22:20:17 -0500 Subject: [PATCH] fix(hosts) now sorts from shortest to longest. Also removed a bad join for live+working sites ref: #27447 --- .../portlets/contentlet/business/HostFactoryImpl.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/HostFactoryImpl.java b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/HostFactoryImpl.java index ed8c6d9fec7c..687e4af271f4 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/HostFactoryImpl.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/HostFactoryImpl.java @@ -119,8 +119,7 @@ public class HostFactoryImpl implements HostFactory { private static final String SITE_IS_LIVE = "cvi.live_inode IS NOT NULL"; @VisibleForTesting - protected static final String SITE_IS_LIVE_OR_STOPPED = "cvi.live_inode IS NOT null or " + - "(cvi.live_inode IS NULL AND cvi.deleted = false )"; + protected static final String SITE_IS_LIVE_OR_STOPPED = "cvi.deleted = false"; private static final String SITE_IS_STOPPED = "cvi.live_inode IS NULL AND cvi" + ".deleted = " + getDBFalse(); @@ -137,7 +136,7 @@ public class HostFactoryImpl implements HostFactory { // query that Exact matches should be at the top of the search results. private static final String PRIORITIZE_EXACT_MATCHES = - "ORDER BY CASE WHEN LOWER(%s) = ? THEN 0 ELSE 1 END"; + "ORDER BY length(%s) "; /** * Default class constructor. @@ -771,9 +770,8 @@ protected Optional> search(final String siteNameFilter, final String dc.setSQL(sqlQuery.toString()); if (UtilMethods.isSet(siteNameFilter)) { // Add the site name filter parameter - dc.addParam("%" + siteNameFilter.trim() + "%"); - // Add the site name filter parameter again, but this time for the exact match - dc.addParam(siteNameFilter.trim().replace("%", "")); + dc.addParam(("%" + siteNameFilter.trim() + "%").replace("%%", "%")); + } if (limit > 0) { dc.setMaxRows(limit);