CRM-17023 put exact matches first
authoreileenmcnaugton <eileen@fuzion.co.nz>
Tue, 25 Aug 2015 08:48:41 +0000 (20:48 +1200)
committereileenmcnaugton <eileen@fuzion.co.nz>
Tue, 25 Aug 2015 08:48:41 +0000 (20:48 +1200)
Without tests it's a bit hard to know the original intent but this makes sense to me

api/v3/Contact.php
tests/phpunit/api/v3/ContactTest.php

index 5f603974ef4038ad07fa4f52249c990e193f3bd1..c0c0e462cb5acc83c5d31c0b76124e254bd2d8a0 100644 (file)
@@ -876,7 +876,7 @@ function civicrm_api3_contact_getquick($params) {
 
   $orderByInner = $orderByOuter = "ORDER BY exactFirst";
   if ($config->includeOrderByClause) {
-    $orderByInner = "ORDER BY sort_name";
+    $orderByInner = "ORDER BY exactFirst, sort_name";
     $orderByOuter .= ", sort_name";
   }
 
index 00ad2b9212f53ec691f4f42e415dff002bab6a38..df5ef1a941ab04433ae5e6640a832d517df4b404 100644 (file)
@@ -2243,9 +2243,12 @@ class api_v3_ContactTest extends CiviUnitTestCase {
 
   /**
    * Test that getquick returns contacts with an exact first name match first.
+   *
+   * Depending on the setting the sort name sort might click in next or not - test!
    */
   public function testGetQuickFirstName() {
     $this->getQuickSearchSampleData();
+    $this->callAPISuccess('Setting', 'create', array('includeOrderByClause' => TRUE));
     $result = $this->callAPISuccess('contact', 'getquick', array(
       'name' => 'Bob',
       'field_name' => 'first_name',
@@ -2263,6 +2266,7 @@ class api_v3_ContactTest extends CiviUnitTestCase {
     $this->callAPISuccess('Setting', 'create', array('includeOrderByClause' => FALSE));
     $result = $this->callAPISuccess('contact', 'getquick', array('name' => 'bob'));
     $this->assertEquals('Bob, Bob', $result['values'][0]['sort_name']);
+    $this->assertEquals('A Bobby, Bobby', $result['values'][1]['sort_name']);
   }
 
   /**