function search_api_page_search_execute in Search API Pages 7
Executes a search.
Parameters
Entity $page: The page for which a search should be executed.
string|null $keys: The keywords to search for, or NULL for a search without keywords.
int $limit: The maximum number of results to return.
Return value
array|false FALSE if no keys were given, no facet filters are present and the page is configured to show no results in this case. Otherwise, the search results as returned by SearchApiQueryInterface::execute().
Throws
SearchApiException If an error occurred during the search.
1 call to search_api_page_search_execute()
- search_api_page_view in ./
search_api_page.pages.inc - Displays a search page.
File
- ./
search_api_page.pages.inc, line 149 - User page callbacks for the Search pages module.
Code
function search_api_page_search_execute(Entity $page, $keys = NULL, $limit = 10) {
$offset = pager_find_page() * $limit;
$options = array(
'search id' => 'search_api_page:' . $page->path,
'search_api_page id' => $page->machine_name,
'parse mode' => $page->options['mode'],
);
if (!empty($page->options['search_api_spellcheck'])) {
$options['search_api_spellcheck'] = TRUE;
}
$query = search_api_query($page->index_id, $options)
->keys($keys)
->range($offset, $limit);
if (!empty($page->options['fields'])) {
$query
->fields($page->options['fields']);
}
if (!empty($page->options['language_filter'])) {
$languages = array_unique(array_map('_search_api_page_map_languages', $page->options['language_filter']));
if (count($languages) == 1) {
$query
->condition('search_api_language', reset($languages));
}
else {
$filter = $query
->createFilter('OR');
foreach ($languages as $lang) {
$filter
->condition('search_api_language', $lang);
}
$query
->filter($filter);
}
}
$results = $query
->execute();
if (!$keys && $page->options['empty_behavior'] === 'blocks' && !search_api_page_query_has_facets($query)) {
return FALSE;
}
return $results;
}