protected function SearchApiElasticsearchElastica::getSearchQueryOptions in Search API Elasticsearch 7
Helper function return associative array with query options.
3 calls to SearchApiElasticsearchElastica::getSearchQueryOptions()
- SearchApiElasticsearchElastica::buildSearchQuery in modules/
elastica/ includes/ SearchApiElasticsearchElastica.inc - Helper function build search query().
- SearchApiElasticsearchElastica::search in modules/
elastica/ includes/ SearchApiElasticsearchElastica.inc - Overrides search().
- SearchApiElasticsearchElastica::searchMultiple in modules/
elastica/ includes/ SearchApiElasticsearchElastica.inc - Implements SearchApiMultiServiceInterface::searchMultiple().
File
- modules/
elastica/ includes/ SearchApiElasticsearchElastica.inc, line 877 - Provides Elastica client for Search API Elasticsearch.
Class
- SearchApiElasticsearchElastica
- Search API Elasticsearch Elastica service class.
Code
protected function getSearchQueryOptions(SearchApiQueryInterface $query) {
// Query options.
$query_options = $query
->getOptions();
// Index fields.
$index_fields = $this
->getIndexFields($query);
// Range.
$query_offset = empty($query_options['offset']) ? 0 : $query_options['offset'];
$query_limit = empty($query_options['limit']) ? 10 : $query_options['limit'];
// Query string.
$query_search_string = NULL;
// Query filter.
$query_search_filter = NULL;
// Query analyzer.
$analyzer = isset($query_options['analyzer']) ? $query_options['analyzer'] : NULL;
// Full text search.
$keys = $query
->getKeys();
if (!empty($keys)) {
if (is_string($keys)) {
$keys = array(
$keys,
);
}
// Full text fields in which to perform the search.
$query_full_text_fields = $query
->getFields();
// Query string.
$search_string = $this
->flattenKeys($keys, $query_options['parse mode']);
if (!empty($search_string)) {
$query_search_string = new Elastica\Query\QueryString($search_string);
$query_search_string
->setFields(array_values($query_full_text_fields));
if ($analyzer) {
$query_search_string
->setParam('analyzer', $analyzer);
}
}
}
// Sort.
try {
$sort = $this
->getSortSearchQuery($query);
} catch (Exception $e) {
watchdog('Elasticsearch', check_plain($e
->getMessage()), array(), WATCHDOG_ERROR);
drupal_set_message($e
->getMessage(), 'error');
}
// Filters.
$parsed_query_filters = $this
->parseFilter($query
->getFilter(), $index_fields);
if (!empty($parsed_query_filters)) {
$query_search_filter = $parsed_query_filters[0];
}
// More Like This.
$mlt = array();
if (isset($query_options['search_api_mlt'])) {
$mlt = $query_options['search_api_mlt'];
}
// Spatials.
$spatials = array();
if (isset($query_options['search_api_location'])) {
$spatials = $query_options['search_api_location'];
}
return array(
'query_offset' => $query_offset,
'query_limit' => $query_limit,
'query_search_string' => $query_search_string,
'query_search_filter' => $query_search_filter,
'sort' => $sort,
'mlt' => $mlt,
'analyzer' => $analyzer,
'spatials' => $spatials,
);
}