You are here

public function ContentHubSearch::buildChronologicalQuery in Acquia Content Hub 8

Builds elasticsearch query to retrieve data in reverse chronological order.

Parameters

array $options: An associative array of options for this query, including:

  • count: number of items per page.
  • start: defines the offset to start from.

Return value

mixed Returns query result.

File

src/ContentHubSearch.php, line 357

Class

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

Namespace

Drupal\acquia_contenthub

Code

public function buildChronologicalQuery(array $options = []) {
  $query['query']['match_all'] = new \stdClass();
  $query['sort']['data.modified'] = 'desc';
  if (!empty($options['sort']) && strtolower($options['sort']) !== 'relevance') {
    $query['sort']['data.modified'] = strtolower($options['sort']);
  }
  $query['filter']['term']['data.type'] = 'node';
  $query['size'] = !empty($options['count']) ? $options['count'] : 10;
  $query['from'] = !empty($options['start']) ? $options['start'] : 0;
  $result = $this
    ->executeSearchQuery($query);
  return $result;
}