protected function SearchApiElasticsearchConnector::getSearchQueryOptions in Elasticsearch Connector 7.5
Same name and namespace in other branches
- 7 modules/elasticsearch_connector_search_api/service.inc \SearchApiElasticsearchConnector::getSearchQueryOptions()
- 7.2 modules/elasticsearch_connector_search_api/service.inc \SearchApiElasticsearchConnector::getSearchQueryOptions()
Helper function return associative array with query options.
1 call to SearchApiElasticsearchConnector::getSearchQueryOptions()
- SearchApiElasticsearchConnector::buildSearchQuery in modules/
elasticsearch_connector_search_api/ service.inc - Helper function build search query().
File
- modules/
elasticsearch_connector_search_api/ service.inc, line 1668 - Provides a Elasticsearch-based service class for the Search API using Elasticsearch Connector module.
Class
- SearchApiElasticsearchConnector
- Search 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 = $this
->handleFulltextSearch($query, $index_fields);
// Query filter.
$query_search_filter = NULL;
// Sort.
try {
$sort = $this
->getSortSearchQuery($query);
} catch (Exception $e) {
watchdog('Elasticsearch Search API', check_plain($e
->getMessage()), array(), WATCHDOG_ERROR);
drupal_set_message($e
->getMessage(), 'error');
}
// Filters.
list($parsed_queries, $parsed_query_filters) = $this
->parseFilter($query
->getFilter(), $index_fields);
if (!empty($parsed_query_filters)) {
$query_search_filter = $parsed_query_filters;
}
if (!empty($parsed_queries)) {
$parsed_queries = reset($parsed_queries);
if (empty($query_search)) {
$query_search = $parsed_queries;
}
else {
$query_search = array(
'bool' => array(
'must' => array(
$query_search,
$parsed_queries,
),
),
);
}
}
// More Like This
$mlt = array();
if (isset($query_options['search_api_mlt'])) {
$mlt = $query_options['search_api_mlt'];
}
// Handle spatial filters.
$spatial = array();
if (isset($query_options['search_api_location'])) {
$spatial = $query_options['search_api_location'];
}
if (isset($query_search_filter['should'])) {
$query_search_filter['minimum_should_match'] = 1;
}
return array(
'query_offset' => $query_offset,
'query_limit' => $query_limit,
'query_search' => $query_search,
'query_search_filter' => $query_search_filter,
'sort' => $sort,
'spatials' => $spatial,
);
}