You are here

protected function SearchApiSolrMultilingualBackend::getLanguageIdFiltersFromQuery in Apache Solr Multilingual 8

Get all languages a solarium query is filtered by.

Parameters

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

\Drupal\search_api\Query\QueryInterface $query: The search_api query the solarium query has been built from.

bool $remove: Wether the language filters should be removed from the solarium query or not. Default is FALSE.

Return value

array Array of language ids.

2 calls to SearchApiSolrMultilingualBackend::getLanguageIdFiltersFromQuery()
SearchApiSolrMultilingualBackend::extractResults in src/Plugin/search_api/backend/SearchApiSolrMultilingualBackend.php
@inheritdoc
SearchApiSolrMultilingualBackend::preQuery in src/Plugin/search_api/backend/SearchApiSolrMultilingualBackend.php
Modify the query before it is sent to solr.

File

src/Plugin/search_api/backend/SearchApiSolrMultilingualBackend.php, line 209
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 getLanguageIdFiltersFromQuery(Query $solarium_query, QueryInterface $query, $remove = FALSE) {
  $language_ids = [];
  $multiple_field_names = $this
    ->getFieldNames($query
    ->getIndex());
  $single_field_names = $this
    ->getFieldNames($query
    ->getIndex(), TRUE);
  $filter_queries = $solarium_query
    ->getFilterQueries();
  foreach ($filter_queries as $filter_query_name => $filter_query) {
    $query_string = $filter_query
      ->getQuery();
    foreach ([
      $single_field_names[SEARCH_API_LANGUAGE_FIELD_NAME],
      $multiple_field_names[SEARCH_API_LANGUAGE_FIELD_NAME],
    ] as $field_name) {
      if (preg_match_all('@' . preg_quote($field_name, '@') . ':"(.+?)"@', $query_string, $matches)) {
        foreach ($matches[1] as $match) {
          $language_ids[] = trim($match, '"');
        }
        if ($remove) {
          $solarium_query
            ->removeFilterQuery($filter_query_name);
        }
      }
    }
  }
  return array_unique($language_ids);
}