You are here

public function ElasticsearchConnectorSearchApiViewsHandlerArgumentMoreLikeThis::query in Elasticsearch Connector 7.5

Same name and namespace in other branches
  1. 7 modules/elasticsearch_connector_search_api/includes/more_like_this_handler.inc \ElasticsearchConnectorSearchApiViewsHandlerArgumentMoreLikeThis::query()
  2. 7.2 modules/elasticsearch_connector_search_api/includes/more_like_this_handler.inc \ElasticsearchConnectorSearchApiViewsHandlerArgumentMoreLikeThis::query()

Set up the query for this argument.

The argument sent may be found at $this->argument.

Overrides SearchApiViewsHandlerArgumentMoreLikeThis::query

File

modules/elasticsearch_connector_search_api/includes/more_like_this_handler.inc, line 63
Contains SearchApiViewsHandlerArgumentMoreLikeThis.

Class

ElasticsearchConnectorSearchApiViewsHandlerArgumentMoreLikeThis
Views argument handler providing a list of related items for search servers supporting the "search_api_mlt" feature.

Code

public function query($group_by = FALSE) {
  $server = $this->query
    ->getIndex()
    ->server();
  if (!$server
    ->supportsFeature('search_api_mlt')) {
    $class = search_api_get_service_info($server->class);
    watchdog('search_api_views', 'The search service "@class" does not offer "More like this" functionality.', array(
      '@class' => $class['name'],
    ), WATCHDOG_ERROR);
    $this->query
      ->abort();
    return;
  }
  $fields = $this->options['fields'] ? $this->options['fields'] : array();
  if (empty($fields)) {
    foreach ($this->query
      ->getIndex()->options['fields'] as $key => $field) {
      $fields[] = $key;
    }
  }
  $mlt = array(
    'id' => $this->argument,
    'fields' => $fields,
    'max_query_terms' => $this->options['max_query_terms'],
    'min_doc_freq' => $this->options['min_doc_freq'],
    'min_term_freq' => $this->options['min_term_freq'],
  );
  $this->query
    ->getSearchApiQuery()
    ->setOption('search_api_mlt', $mlt);
}