You are here

protected function SearchApiSolrMultilingualBackend::extractResults in Apache Solr Multilingual 8

@inheritdoc

File

src/Plugin/search_api/backend/SearchApiSolrMultilingualBackend.php, line 113
Contains \Drupal\as_search\Plugin\search_api\backend\ASSearchApiSolrBackend.

Class

SearchApiSolrMultilingualBackend
Plugin annotation @SearchApiBackend( id = "search_api_solr_multilingual", label = @Translation("Solr Multilingual"), description = @Translation("Index items using an Apache Solr Multilingual search server.") )

Namespace

Drupal\apachesolr_multilingual\Plugin\search_api\backend

Code

protected function extractResults(QueryInterface $query, ResultInterface $result) {
  if ($this->configuration['retrieve_data']) {
    $language_ids = $this
      ->getLanguageIdFiltersFromQuery($result
      ->getQuery(), $query);
    $index = $query
      ->getIndex();
    $single_field_names = $this
      ->getFieldNames($index, TRUE);
    $data = $result
      ->getData();
    foreach ($data['response']['docs'] as &$doc) {
      $language_id = $doc[$single_field_names[SEARCH_API_LANGUAGE_FIELD_NAME]];
      foreach (array_keys($doc) as $language_specific_field_name) {
        $field_name = SearchApiSolrMultilingualUtility::getSolrDynamicFieldNameForLanguageSpecificSolrDynamicFieldName($language_specific_field_name);
        if ($field_name != $language_specific_field_name) {
          if (SearchApiSolrMultilingualUtility::getLangaugeIdFromLanguageSpecificSolrDynamicFieldName($language_specific_field_name) == $language_id) {
            $doc[$field_name] = $doc[$language_specific_field_name];
          }
          unset($doc[$language_specific_field_name]);
        }
      }
    }
    $new_response = new Response(json_encode($data), $result
      ->getResponse()
      ->getHeaders());
    $result = new Result(NULL, $result
      ->getQuery(), $new_response);
  }
  return parent::extractResults($query, $result);
}