You are here

protected function SearchApiElasticsearchQuery::flattenKeys in Search API Elasticsearch 7.2

Flatten keys for full text search.

Parameters

$keys:

string $parse_mode:

array $full_text_fields:

Return value

string

1 call to SearchApiElasticsearchQuery::flattenKeys()
SearchApiElasticsearchQuery::build in includes/SearchApiElasticsearchQuery.inc
Build Elastica query for Elasticsearch.

File

includes/SearchApiElasticsearchQuery.inc, line 494

Class

SearchApiElasticsearchQuery
@file

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 '';
  }
}