You are here

protected function SearchApiSolrBackend::ensureLanguageCondition 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::ensureLanguageCondition()

Ensures the given Search API query has a language condition applied.

Parameters

\Drupal\search_api\Query\QueryInterface $query: The Search API query.

Return value

array An array of language IDs applied to the query.

9 calls to SearchApiSolrBackend::ensureLanguageCondition()
SearchApiSolrBackend::createFilterQueries in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Recursively transforms conditions into a flat array of Solr filter queries.
SearchApiSolrBackend::getAutocompleteFields in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Get the fields to search for autocomplete terms.
SearchApiSolrBackend::getAutocompleteSuggestions in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Implements autocomplete compatible to AutocompleteBackendInterface.
SearchApiSolrBackend::getMoreLikeThisQuery in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Changes the query to a "More Like This" query.
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:

... See full list

File

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

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

protected function ensureLanguageCondition(QueryInterface $query) {

  /** @var \Drupal\search_api\Entity\Index $index */
  $index = $query
    ->getIndex();
  $settings = Utility::getIndexSolrSettings($index);
  $language_ids = $query
    ->getLanguages();

  // If there are no languages set, we need to set them. As an example, a
  // language might be set by a filter in a search view.
  if (empty($language_ids)) {
    if (!$query
      ->hasTag('views') && $settings['multilingual']['limit_to_content_language']) {

      // Limit the language to the current language being used.
      $language_ids[] = \Drupal::languageManager()
        ->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
        ->getId();
    }
    else {

      // If the query is generated by views and/or the query isn't limited
      // by any languages we have to search for all languages using their
      // specific fields.
      $language_ids = array_keys(\Drupal::languageManager()
        ->getLanguages());
    }
  }
  if ($settings['multilingual']['include_language_independent']) {
    $language_ids[] = LanguageInterface::LANGCODE_NOT_SPECIFIED;

    // LanguageInterface::LANGCODE_NOT_APPLICABLE never appears in Search API
    // at the moment.
  }
  $query
    ->setLanguages(array_unique($language_ids));
  return $language_ids;
}