public function SearchApiQuery::__construct in Search API 7
Constructs a new search query.
Parameters
SearchApiIndex $index: The index the query should be executed on.
array $options: Associative array of options configuring this query. Recognized options are:
- conjunction: The type of conjunction to use for this query - either 'AND' or 'OR'. 'AND' by default. This only influences the search keys, filters will always use AND by default.
- 'parse mode': The mode with which to parse the $keys variable, if it is set and not already an array. See SearchApiQuery::parseModes() for recognized parse modes.
- languages: The languages to search for, as an array of language IDs. If not specified, all languages will be searched. Language-neutral content (LANGUAGE_NONE) is always searched.
- offset: The position of the first returned search results relative to the whole result in the index.
- limit: The maximum number of search results to return. -1 means no limit.
- 'filter class': Can be used to change the SearchApiQueryFilterInterface implementation to use.
- 'search id': A string that will be used as the identifier when storing this search in the Search API's static cache.
- 'skip result count': If present and set to TRUE, the result's "result count" key will not be needed. Service classes can check for this option to possibly avoid executing expensive operations to compute the result count in cases where it is not needed.
- search_api_access_account: The account which will be used for entity access checks, if available and enabled for the index.
- search_api_bypass_access: If set to TRUE, entity access checks will be skipped, even if enabled for the index.
All options are optional. Third-party modules might define and use other options not listed here.
Throws
SearchApiException If a search on that index (or with those options) won't be possible.
Overrides SearchApiQueryInterface::__construct
File
- includes/
query.inc, line 444 - Contains SearchApiQueryInterface and SearchApiQuery.
Class
- SearchApiQuery
- Provides a standard implementation of the SearchApiQueryInterface.
Code
public function __construct(SearchApiIndex $index, array $options = array()) {
if (empty($index->options['fields'])) {
throw new SearchApiException(t("Can't search an index which hasn't got any fields defined."));
}
if (empty($index->enabled)) {
throw new SearchApiException(t("Can't search a disabled index."));
}
if (isset($options['parse mode'])) {
$modes = $this
->parseModes();
if (!isset($modes[$options['parse mode']])) {
throw new SearchApiException(t('Unknown parse mode: @mode.', array(
'@mode' => $options['parse mode'],
)));
}
}
$this->index = $index;
$this->options = $options + array(
'conjunction' => 'AND',
'parse mode' => 'terms',
'filter class' => 'SearchApiQueryFilter',
'search id' => __CLASS__,
);
$this->filter = $this
->createFilter('AND');
$this->sort = array();
}