function example_create_autocomplete_query in Search API Autocomplete 7
Create the query that would be issued for the given search for the complete keys.
Parameters
SearchApiAutocompleteSearch $search: The search for which to create the query.
$complete: A string containing the complete search keys.
$incomplete: A string containing the incomplete last search key.
Return value
SearchApiQueryInterface The query that would normally be executed when only $complete was entered as the search keys for the given search.
Throws
SearchApiException If the query couldn't be created.
1 string reference to 'example_create_autocomplete_query'
- hook_search_api_autocomplete_types in ./
search_api_autocomplete.api.php - Inform the module about types of searches for which autocompletion is available.
File
- ./
search_api_autocomplete.api.php, line 312 - Hooks provided by the Search API autocomplete module.
Code
function example_create_autocomplete_query(SearchApiAutocompleteSearch $search, $complete, $incomplete) {
$query = search_api_query($search->index_id);
if ($complete) {
$query
->keys($complete);
}
if (!empty($search->options['custom']['extra'])) {
list($f, $v) = explode('=', $search->options['custom']['extra'], 2);
$query
->condition($f, $v);
}
if (!empty($search->options['custom']['user_filters'])) {
foreach (explode("\n", $search->options['custom']['user_filters']) as $line) {
list($f, $v) = explode('=', $line, 2);
$query
->condition($f, $v);
}
}
return $query;
}