You are here

protected function SearchApiSolrBackend::setFields in Search API Solr 8.2

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::setFields()
  2. 4.x src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::setFields()

Set the list of fields Solr should return as result.

Parameters

\Solarium\QueryType\Select\Query\Query $solarium_query: The solr query.

array $field_names: The field names.

array $fields_to_be_retrieved: The filed values to be retrieved form Solr.

1 call to SearchApiSolrBackend::setFields()
SearchApiSolrBackend::search in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Options on $query prefixed by 'solr_param_' will be passed natively to Solr as query parameter without the prefix. For example you can set the "Minimum Should Match" parameter 'mm' to '75%' like this:

File

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

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

protected function setFields(Query $solarium_query, array $field_names, array $fields_to_be_retrieved = []) {

  // 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';
  }
  $returned_fields = [];
  if (!empty($this->configuration['retrieve_data'])) {

    // If Search API provides information about the fields to retrieve,
    // limit the fields accordingly. ...
    foreach ($fields_to_be_retrieved as $field_name) {
      if (isset($field_names[$field_name])) {
        $returned_fields[] = $field_names[$field_name];
      }
    }
    if ($returned_fields) {
      $returned_fields = array_merge($returned_fields, $required_fields);
    }
    else {
      $returned_fields = [
        '*',
        $field_names['search_api_relevance'],
      ];
    }
  }
  else {
    $returned_fields = $required_fields;
  }
  $solarium_query
    ->setFields(array_unique($returned_fields));
}