From 51e61eae7bef9c4ecf5e6a8e2e5af20fab4469e4 Mon Sep 17 00:00:00 2001 From: Adam Roses Wight Date: Thu, 11 Apr 2013 16:30:03 -0700 Subject: [PATCH] Respect includeOrderByClause in quicksearch CRM-12326 Name search is not using indexes correctly --- api/v3/Contact.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/api/v3/Contact.php b/api/v3/Contact.php index 7ccbbfb473..cb603cb601 100644 --- a/api/v3/Contact.php +++ b/api/v3/Contact.php @@ -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 -- 2.25.1