public function BasicTitleSearchService::search in Fast Autocomplete 7
Implements SearchServiceInterface::search().
Parameters
string $key: The key to use in the search.
string $language: The language to use in the search.
Return value
array The results array containing the resulting nids.
Overrides AbstractSearchService::search
File
- src/
SearchService/ BasicTitleSearchService.php, line 21
Class
- BasicTitleSearchService
- Fast Autocomplete backend service class for basic title search on nodes.
Namespace
Drupal\fac\SearchServiceCode
public function search($key, $language) {
$result = array();
$settings = variable_get('fac_backend_service_settings', array());
$query = db_select('node', 'n')
->fields('n', array(
'nid',
))
->condition('n.title', '%' . db_like($key) . '%', 'LIKE')
->condition('n.status', 1, '=')
->condition('n.language', array(
LANGUAGE_NONE,
$language,
), 'IN')
->orderBy('n.title')
->range(0, isset($settings['number_of_results']) ? $settings['number_of_results'] : 5)
->addTag('node_access');
// Allow other modules to modify the query.
drupal_alter('fac_basic_title_search_query', $query);
$nids = $query
->execute()
->fetchCol();
foreach ($nids as $nid) {
$result['items'][] = array(
'entity_type' => 'node',
'etid' => $nid,
);
}
return $result;
}