CRM-17023 exactfirst doesn't work
authoreileenmcnaugton <eileen@fuzion.co.nz>
Fri, 14 Aug 2015 03:20:49 +0000 (15:20 +1200)
committereileenmcnaugton <eileen@fuzion.co.nz>
Sun, 16 Aug 2015 02:25:33 +0000 (14:25 +1200)
api/v3/Contact.php
settings/Search.setting.php
tests/phpunit/api/v3/ContactTest.php

index eb6b5d73583d22ef82a026be99664ee3b95890fd..ae02456ccaed4b2ba64847ac497308d696b2f11e 100644 (file)
@@ -853,7 +853,7 @@ function civicrm_api3_contact_getquick($params) {
 
   //CRM-5954
   $query = "
-        SELECT DISTINCT(id), data, sort_name {$selectAliases}
+        SELECT DISTINCT(id), data, sort_name {$selectAliases}, exactFirst
         FROM   (
             ( SELECT 0 as exactFirst, cc.id as id, CONCAT_WS( ' :: ', {$actualSelectElements} ) as data {$select}
             FROM   civicrm_contact cc {$from}
index 5f33e75847e2a2a6da304482f2b072dc26426e72..a2324b7dc49aec48b67f751f3a07f05033fe195e 100644 (file)
@@ -94,4 +94,22 @@ return array(
     'description' => NULL,
     'help_text' => NULL,
   ),
+  'includeOrderByClause' => array(
+    'group_name' => 'Search Preferences',
+    'group' => 'Search Preferences',
+    'name' => 'includeOrderByClause',
+    'prefetch' => 1,
+    // prefetch causes it to be cached in config settings. Usually this is a transitional setting. Some things like urls are permanent. Remove this comment if you have assessed & it should be permanent
+    'config_only' => 1,
+    //@todo - see https://wiki.civicrm.org/confluence/display/CRMDOC/Settings+Reference#SettingsReference-Convertingaconfigobjecttoasetting on removing this deprecated value
+    'type' => 'Boolean',
+    'quick_form_type' => 'YesNo',
+    'default' => 1,
+    'add' => '4.6',
+    'title' => 'Include Order By Clause',
+    'is_domain' => 1,
+    'is_contact' => 0,
+    'description' => 'If disabled, the search results will not be ordered. This may improve response time on search results on large datasets',
+    'help_text' => NULL,
+  ),
 );
index 985c94153b305ef94169673cca7fad0e4fc997da..3759909cf880a17f701c70fb0a2f99fa30ea5d8d 100644 (file)
@@ -2148,6 +2148,34 @@ class api_v3_ContactTest extends CiviUnitTestCase {
     $this->callAPISuccess('contact', 'getquick', array('name' => 'b', 'check_permissions' => TRUE));
   }
 
+  /**
+   * Test that getquick returns contacts with an exact first name match first.
+   */
+  public function testGetQuickExactFirst() {
+    $this->getQuickSearchSampleData();
+    $result = $this->callAPISuccess('contact', 'getquick', array('name' => 'b'));
+    $this->assertEquals('A Bobby, Bobby', $result['values'][0]['sort_name']);
+    $result = $this->callAPISuccess('contact', 'getquick', array('name' => 'bob'));
+    $this->assertEquals('A Bobby, Bobby', $result['values'][0]['sort_name']);
+    $this->callAPISuccess('Setting', 'create', array('includeOrderByClause' => FALSE));
+    $result = $this->callAPISuccess('contact', 'getquick', array('name' => 'bob'));
+    $this->assertEquals('Bob, Bob', $result['values'][0]['sort_name']);
+  }
+
+  /**
+   * Set up some sample data for testing quicksearch.
+   */
+  public function getQuickSearchSampleData() {
+    $contacts = array(
+      array('first_name' => 'Bob', 'last_name' => 'Bob'),
+      array('first_name' => 'Bobby', 'last_name' => 'A Bobby'),
+    );
+    foreach ($contacts as $type => $contact) {
+      $contact['contact_type'] = 'Individual';
+      $this->callAPISuccess('Contact', 'create', $contact);
+    }
+  }
+
   /**
    * Test get ref api - gets a list of references to an entity.
    */