You are here

protected function SearchApiSolrBackend::getRequiredFields in Search API Solr 4.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::getRequiredFields()

Get the list of fields Solr must return as result.

Parameters

\Drupal\search_api\Query\QueryInterface $query: The \Drupal\search_api\Query\Query object representing the executed search query.

Return value

array An array of required fields as strings.

Throws

\Drupal\search_api\SearchApiException

1 call to SearchApiSolrBackend::getRequiredFields()
SearchApiSolrBackend::setFields in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Set the list of fields Solr should return as result.

File

src/Plugin/search_api/backend/SearchApiSolrBackend.php, line 1829

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

protected function getRequiredFields(QueryInterface $query) {
  $index = $query
    ->getIndex();
  $field_names = $this
    ->getSolrFieldNames($index);

  // The list of fields Solr must return to built a Search API result.
  $required_fields = [
    $field_names['search_api_id'],
    $field_names['search_api_language'],
    $field_names['search_api_relevance'],
  ];
  if (!$this->configuration['site_hash']) {
    $required_fields[] = 'hash';
  }
  if (Utility::hasIndexJustSolrDocumentDatasource($index)) {
    $config = $this
      ->getDatasourceConfig($index);
    $extra_fields = [
      'label_field',
      'url_field',
    ];
    foreach ($extra_fields as $config_key) {
      if (!empty($config[$config_key])) {
        $required_fields[] = $config[$config_key];
      }
    }
  }
  return array_filter($required_fields);
}