You are here

public function ContentHubSearch::getFilters in Acquia Content Hub 8

Helper function to build elasticsearch query for terms using AND operator.

Parameters

string $search_term: Search term.

Return value

mixed Returns query result.

File

src/ContentHubSearch.php, line 89

Class

ContentHubSearch
Perform queries to the Content Hub "_search" endpoint [Elasticsearch].

Namespace

Drupal\acquia_contenthub

Code

public function getFilters($search_term) {
  if ($search_term) {
    $items = array_map('trim', explode(',', $search_term));
    $last_item = array_pop($items);
    $query['query'] = [
      'query_string' => [
        'query' => $last_item,
        'default_operator' => 'and',
      ],
    ];
    $query['_source'] = TRUE;
    $query['highlight'] = [
      'fields' => [
        '*' => new \stdClass(),
      ],
    ];
    $result = $this
      ->executeSearchQuery($query);
    return $result ? $result['hits'] : FALSE;
  }
}