From 08f4ab8daae07d5a7fdec4309849170fa28d43fd Mon Sep 17 00:00:00 2001 From: eileenmcnaugton Date: Fri, 14 Aug 2015 15:20:49 +1200 Subject: [PATCH] CRM-17023 exactfirst doesn't work --- api/v3/Contact.php | 2 +- settings/Search.setting.php | 18 ++++++++++++++++++ tests/phpunit/api/v3/ContactTest.php | 28 ++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/api/v3/Contact.php b/api/v3/Contact.php index eb6b5d7358..ae02456cca 100644 --- a/api/v3/Contact.php +++ b/api/v3/Contact.php @@ -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} diff --git a/settings/Search.setting.php b/settings/Search.setting.php index 5f33e75847..a2324b7dc4 100644 --- a/settings/Search.setting.php +++ b/settings/Search.setting.php @@ -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, + ), ); diff --git a/tests/phpunit/api/v3/ContactTest.php b/tests/phpunit/api/v3/ContactTest.php index 985c94153b..3759909cf8 100644 --- a/tests/phpunit/api/v3/ContactTest.php +++ b/tests/phpunit/api/v3/ContactTest.php @@ -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. */ -- 2.25.1