You are here

protected function SearchApiElasticsearchConnector::handleStringQuery in Elasticsearch Connector 7.5

Same name and namespace in other branches
  1. 7 modules/elasticsearch_connector_search_api/service.inc \SearchApiElasticsearchConnector::handleStringQuery()
  2. 7.2 modules/elasticsearch_connector_search_api/service.inc \SearchApiElasticsearchConnector::handleStringQuery()

Build the string_query for the Elasticsearch request.

Parameters

SearchApiQueryInterface $query:

array $index_fields:

Return value

array

1 call to SearchApiElasticsearchConnector::handleStringQuery()
SearchApiElasticsearchConnector::handleFulltextSearch in modules/elasticsearch_connector_search_api/service.inc
Helper function. Handle freetext search parameters.

File

modules/elasticsearch_connector_search_api/service.inc, line 1543
Provides a Elasticsearch-based service class for the Search API using Elasticsearch Connector module.

Class

SearchApiElasticsearchConnector
Search service class.

Code

protected function handleStringQuery(SearchApiQueryInterface $query, $index_fields) {
  $query_search_string = array();
  if (!$this
    ->isWildcardQuery($query)) {

    // Get query options.
    $query_options = $query
      ->getOptions();
    $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 = array(
          'query_string' => array(),
        );
        $query_search_string['query_string']['query'] = $search_string;
        foreach ($query_full_text_fields as $fulltext_field) {
          $boost = isset($index_fields[$fulltext_field]['boost']) ? '^' . $index_fields[$fulltext_field]['boost'] : '';
          $query_search_string['query_string']['fields'][] = $fulltext_field . $boost;
        }
      }
    }
  }
  return $query_search_string;
}