/** * Lets modules alter a search query before executing it. * * @param SearchApiQueryInterface $query * The search query being executed. */ function hook_search_api_query_alter(SearchApiQueryInterface $query) { // Exclude entities with ID 0. (Assume the ID field is always indexed.) if ($query->getIndex()->getEntityType()) { $info = entity_get_info($query->getIndex()->getEntityType()); $query->condition($info['entity keys']['id'], 0, '<>'); } }
/** * Implements hook_search_api_query_alter(). * * This example hook implementation shows how a custom module could fix the * problem with Views contextual filters in a specific context. */ function example_search_api_query_alter(SearchApiQueryInterface $query) { // Check whether this is an appropriate automcomplete query. if ($query->getOption('search id') === 'search_api_autocomplete:example') { // If it is, add the necessary filters that would otherwise be added by // contextual filters. This is easy if the argument comes from the global // user or a similar global source. If the argument comes from the URL or // some other page-specific source, however, you would need to somehow pass // that information along to this function. global $user; $query->condition('group', $user->data['group']); } }
/** * Lets modules alter a search query before executing it. * * @param SearchApiQueryInterface $query * The SearchApiQueryInterface object representing the search query. */ function hook_search_api_query_alter(SearchApiQueryInterface $query) { $info = entity_get_info($index->item_type); $query->condition($info['entity keys']['id'], 0, '!='); }