protected function SearchApiSolrBackend::setAutocompleteSuggesterQuery in Search API Solr 4.x
Same name and namespace in other branches
- 8.3 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::setAutocompleteSuggesterQuery()
- 8.2 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::setAutocompleteSuggesterQuery()
Set the suggester parameters for the solarium autocomplete query.
Parameters
\Drupal\search_api\Query\QueryInterface $query: A query representing the completed user input so far.
\Drupal\search_api_solr\Solarium\Autocomplete\Query $solarium_query: A Solarium autocomplete query.
string $user_input: The user input.
array $options: (optional) An array of options. e.g: 'dictionary' as string, 'context_filter_tags' as array of strings.
1 call to SearchApiSolrBackend::setAutocompleteSuggesterQuery()
- SearchApiSolrBackend::getSuggesterSuggestions in src/
Plugin/ search_api/ backend/ SearchApiSolrBackend.php
File
- src/
Plugin/ search_api/ backend/ SearchApiSolrBackend.php, line 3721
Class
- SearchApiSolrBackend
- Apache Solr backend for search api.
Namespace
Drupal\search_api_solr\Plugin\search_api\backendCode
protected function setAutocompleteSuggesterQuery(QueryInterface $query, AutocompleteQuery $solarium_query, $user_input, array $options = []) {
$langcodes = $this
->ensureLanguageCondition($query);
if (isset($options['context_filter_tags'])) {
if (in_array('drupal/langcode:multilingual', $options['context_filter_tags'])) {
if ($langcodes && count($langcodes) === 1) {
$langcode = reset($langcodes);
$options['context_filter_tags'] = str_replace('drupal/langcode:multilingual', 'drupal/langcode:' . $langcode, $options['context_filter_tags']);
$options['dictionary'] = $langcode;
}
else {
// Use multiple dictionaries and langcodes.
$tag_name = Utility::encodeSolrName('drupal/langcode:');
$options['context_filter_tags'] = str_replace('drupal/langcode:multilingual', '(' . $tag_name . implode(' ' . $tag_name, $langcodes) . ')', $options['context_filter_tags']);
$options['dictionary'] = $langcodes;
}
}
else {
foreach ($options['context_filter_tags'] as $key => $tag) {
if (strpos($tag, 'drupal/langcode:') === 0) {
$langcode_array = explode(':', $tag);
if (isset($langcode_array[1]) && 'any' !== $langcode_array[1]) {
$options['dictionary'] = $langcode_array[1] ?: LanguageInterface::LANGCODE_NOT_SPECIFIED;
break;
}
}
}
}
if (empty($options['dictionary'])) {
foreach ($options['context_filter_tags'] as $key => $tag) {
if (strpos($tag, 'drupal/langcode:') === 0) {
unset($options['context_filter_tags'][$key]);
break;
}
}
}
}
$suggester_component = $solarium_query
->getSuggester();
$suggester_component
->setQuery($user_input);
$suggester_component
->setDictionary(!empty($options['dictionary']) ? $options['dictionary'] : LanguageInterface::LANGCODE_NOT_SPECIFIED);
if (!empty($options['context_filter_tags'])) {
$suggester_component
->setContextFilterQuery(Utility::buildSuggesterContextFilterQuery($options['context_filter_tags']));
}
$suggester_component
->setCount($query
->getOption('limit') ?? 10);
// The search_api_autocomplete module highlights by itself.
$solarium_query
->addParam('suggest.highlight', FALSE);
}