protected function SearchApiSolrBackend::ensureLanguageCondition in Search API Solr 8.3
Same name and namespace in other branches
- 4.x 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.
2 calls to SearchApiSolrBackend::ensureLanguageCondition()
- SearchApiSolrBackend::getAutocompleteSuggestions in src/
Plugin/ search_api/ backend/ SearchApiSolrBackend.php - Implements autocomplete compatible to AutocompleteBackendInterface.
- 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 1619
Class
- SearchApiSolrBackend
- Apache Solr backend for search api.
Namespace
Drupal\search_api_solr\Plugin\search_api\backendCode
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;
$language_ids[] = LanguageInterface::LANGCODE_NOT_APPLICABLE;
}
$query
->setLanguages($language_ids);
return $language_ids;
}