//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}
'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,
+ ),
);
$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.
*/