You are here

protected function SearchApiElasticsearchBackend::flattenKeys in Elasticsearch Connector 8

Return a full text search query.

TODO: better handling of parse modes.

1 call to SearchApiElasticsearchBackend::flattenKeys()
SearchApiElasticsearchBackend::getSearchQueryOptions in src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php
Helper function return associative array with query options.

File

src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php, line 865
Contains the SearchApiElasticsearchBackend object.

Class

SearchApiElasticsearchBackend
Plugin annotation @SearchApiBackend( id = "elasticsearch", label = @Translation("Elasticsearch"), description = @Translation("Index items using an Elasticsearch server.") )

Namespace

Drupal\elasticsearch_connector\Plugin\search_api\backend

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 ($keys as $key_nr => $key) {

    // We cannot use \Drupal\Core\Render\Element::children() anymore because
    // $keys is not a valid render array.
    if ($key_nr[0] === '#' || !$key) {
      continue;
    }
    if (is_array($key)) {
      $values[] = $this
        ->flattenKeys($key);
    }
    elseif (is_string($key)) {

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