You are here

protected function ESQueryGenerator::getQueryFromString in Acquia Content Hub 8

Converts a query string to a query array.

1 call to ESQueryGenerator::getQueryFromString()
ESQueryGenerator::getElasticSearchQuery in acquia_contenthub_subscriber/src/ESQueryGenerator.php
Obtains an Elasticsearch Query.

File

acquia_contenthub_subscriber/src/ESQueryGenerator.php, line 184

Class

ESQueryGenerator
Elasticsearch query generator.

Namespace

Drupal\acquia_contenthub_subscriber

Code

protected function getQueryFromString($queryString) {
  $query = [
    'bool' => [
      'must' => [],
    ],
  ];

  // Explode the search term into parts, ignore any that are null/empty.
  $queryStringTokens = preg_split("/[^a-zA-Z\\d:]+/", $queryString);
  foreach ($queryStringTokens as $token) {
    if (strlen($token) != 0) {
      $query['bool']['must'][] = [
        'match' => [
          '_all' => "*{$token}*",
        ],
      ];
    }
  }
  return $query;
}