You are here

protected function SearchApiElasticsearchConnector::flattenKeys in Elasticsearch Connector 7

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

Return a full text search query.

TODO: better handling of parse modes.

1 call to SearchApiElasticsearchConnector::flattenKeys()
SearchApiElasticsearchConnector::handleStringQuery in modules/elasticsearch_connector_search_api/service.inc
Build the string_query for the Elasticsearch request.

File

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

Class

SearchApiElasticsearchConnector
Search service class.

Code

protected function flattenKeys($keys, $parse_mode = '', $full_text_fields = array()) {
  $conjunction = isset($keys['#conjunction']) ? $keys['#conjunction'] : 'AND';
  $negation = !empty($keys['#negation']);
  $values = array();
  foreach (element_children($keys) as $key) {
    $value = $keys[$key];
    if (empty($value)) {
      continue;
    }
    if (is_array($value)) {
      $values[] = $this
        ->flattenKeys($value);
    }
    elseif (is_string($value)) {

      // If parse mode is not "direct": quote the keyword.
      if ($parse_mode !== 'direct') {
        $value = '"' . $value . '"';
      }
      $values[] = $value;
    }
  }
  if (!empty($values)) {
    return ($negation === TRUE ? 'NOT ' : '') . '(' . implode(" {$conjunction} ", $values) . ')';
  }
  else {
    return '';
  }
}