Respect includeOrderByClause in quicksearch
authorAdam Roses Wight <awight@wikimedia.org>
Thu, 11 Apr 2013 23:30:03 +0000 (16:30 -0700)
committerAdam Roses Wight <awight@wikimedia.org>
Tue, 23 Apr 2013 18:16:23 +0000 (11:16 -0700)
CRM-12326 Name search is not using indexes correctly

api/v3/Contact.php

index 7ccbbfb4730818e17b7053c49afea60bf3132fba..cb603cb60175f3e19d4fc62ef80aa63900c447d8 100644 (file)
@@ -732,6 +732,13 @@ function civicrm_api3_contact_getquick($params) {
       ";
   }
 
+  $orderByInner = "";
+  $orderByOuter = "ORDER BY exactFirst";
+  if ($config->includeOrderByClause) {
+    $orderByInner = "ORDER BY sort_name";
+    $orderByOuter .= ", sort_name";
+  }
+
   //CRM-5954
   $query = "
         SELECT DISTINCT(id), data, sort_name {$selectAliases}
@@ -748,10 +755,10 @@ function civicrm_api3_contact_getquick($params) {
     {$aclFrom}
     {$additionalFrom} {$includeEmailFrom}
     {$whereClause}
-    ORDER BY sort_name
+    {$orderByInner}
     LIMIT 0, {$limit} )
 ) t
-ORDER BY exactFirst, sort_name
+{$orderByOuter}
 LIMIT    0, {$limit}
     ";
   // send query to hook to be modified if needed