- Issue created by @SerShevchyk
- Status changed to Needs review
over 1 year ago 12:58pm 22 August 2023 - last update
over 1 year ago 34 pass - Status changed to Needs work
over 1 year ago 7:49pm 2 September 2023 - 🇺🇦Ukraine SerShevchyk Lutsk
The last patch applied well but autocomplete doesn't work and in the logs, I can see a new error:
Could not load the following items on index Remote Data: "solr_document/1000740", "solr_document/1000713", "solr_document/1000608", "solr_document/1000634", "solr_document/1000699", "solr_document/1000633", "solr_document/1000548", "solr_document/1000547", "solr_document/1000534", "solr_document/1000530".
- 🇮🇳India anweshasinha
Hi,
I have created patch for the search api autocomplete issue received above. Please review once. - Status changed to Needs review
over 1 year ago 8:19am 6 September 2023 - last update
over 1 year ago 34 pass - Status changed to Needs work
over 1 year ago 12:25am 20 September 2023 - 🇺🇦Ukraine SerShevchyk Lutsk
Any of the patches above didn't help with the problem on my project. I have created my own plugin and it helps me with the task, maybe it will be helpful for other developers. But we need to create a patch to this module and search_api.
<?php namespace Drupal\custom\Plugin\search_api_autocomplete\suggester; use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Component\Utility\Xss; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginFormInterface; use Drupal\Core\Url; use Drupal\search_api\LoggerTrait; use Drupal\search_api\Plugin\PluginFormTrait; use Drupal\search_api\Processor\ProcessorPluginManager; use Drupal\search_api\Query\QueryInterface; use Drupal\search_api\SearchApiException; use Drupal\search_api\Utility\Utility; use Drupal\search_api_autocomplete\Plugin\search_api_autocomplete\suggester\LiveResults; use Drupal\search_api_autocomplete\SearchApiAutocompleteException; use Drupal\search_api_autocomplete\Suggester\SuggesterPluginBase; use Drupal\search_api_autocomplete\Suggestion\SuggestionFactory; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides a suggester plugin that displays live results. * * @SearchApiAutocompleteSuggester( * id = "solr_document_live_results", * label = @Translation("Display live results (SolrDocument)"), * description = @Translation("Display live results to visitors as they type. (Unless the server is configured to find partial matches, this will most likely only produce results once the visitor has finished typing.)"), * ) */ class SolrDocumentLiveResults extends LiveResults implements PluginFormInterface { /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { /** @var static $plugin */ $plugin = parent::create($container, $configuration, $plugin_id, $plugin_definition); return $plugin; } /** * {@inheritdoc} */ public function getAutocompleteSuggestions(QueryInterface $query, $incomplete_key, $user_input) { $fulltext_fields = $this->configuration['fields']; $index = $query->getIndex(); if ($fulltext_fields) { // Take care only to set fields that are still indexed fulltext fields. $index_fields = $index->getFulltextFields(); $fulltext_fields = array_intersect($fulltext_fields, $index_fields); if ($fulltext_fields) { $query->setFulltextFields($fulltext_fields); } else { $args = [ '@suggester' => $this->label(), '@search' => $this->getSearch()->label(), '@index' => $index->label(), ]; $this->getLogger()->warning('Only invalid fulltext fields set for suggester "@suggester" in autocomplete settings for search "@search" on index "@index".', $args); } } $query->keys($user_input); try { $results = $query->execute(); } catch (SearchApiException $e) { // If the query fails, there's nothing we can do about that. return []; } // Pre-load the result items for performance reasons. $item_ids = array_keys($results->getResultItems()); // Group the requested items by datasource. This will also later be used to // determine whether all items were loaded successfully. $ids = []; foreach ($item_ids as $item_id) { [$datasource_id, $raw_id] = Utility::splitCombinedId($item_id); $ids[$raw_id] = $item_id; } $objects = []; try { // Query the index for the Solr documents. $results = $index->query() ->addCondition('search_api_id', array_keys($ids), 'IN') ->execute() ->getResultItems(); foreach ($results as $id => $result) { $objects[$id] = \Drupal::getContainer()->get('solr_document.factory')->create($result); } } catch (SearchApiException $e) { // Couldn't load items from server, return an empty array. } $factory = new SuggestionFactory($user_input); $suggestions = []; foreach ($results as $item_id => $item) { // If the result object could not be loaded, there's little we can do // here. if (empty($objects[$item_id])) { continue; } $object = $objects[$item_id]; $item->setOriginalObject($object); $label = $object->get('label')->getValue()[0]; $id = $object->get('id')->getValue()[0]; $url = Url::fromUserInput("/other-recognized-documents/$id"); $suggestions[] = $factory->createUrlSuggestion($url, $label); } return $suggestions; } }
- Status changed to Closed: duplicate
over 1 year ago 10:13am 1 October 2023 - 🇦🇹Austria drunken monkey Vienna, Austria
This was a bug in the Solr module and is already fixed, see 🐛 Fix SolrDocument::loadMultiple() Fixed . Please just update to the latest version of the Solr module.