Score:1

How to create a Solr search with partial matches and autocomplete?

cn flag

I configured a search box for a drupal site and am a bit confused on how to get a search working with partial matches and a sensible autocomplete.

Some basic details:

  • Drupal: 9.3.9
  • Modules: Search API, Search API Autocomplete, Search API Solr
  • Solr: 8.11.1

The search searches through different fields from several types of content. At first I set the field types to "Fulltext". Then I noticed that only complete words are matched. So searching for "idea" would not find pages containing "ideas". That worked when I changed all field types to "Fulltext ngram". But: Now the autocomplete suggests all the partials as well. So entering "super" would suggest "superh", "superhe" and "superhero". That's not really useful for the site's visitors.

What I already tried: The autocomplete uses the suggester "Retrieve from server". I tried to enable the additional module "search_api_solr_autocomplete". That adds three more suggesters, "Solr Spellcheck", "Solr Suggester" and "Solr Terms". The spellcheck suggester did not yield any autocomplete suggestions. Neither did the Solr Suggester. Solr Terms does the same as "Retrieve from server", it suggests all intermediate steps between the search word and the finished term, letter for letter.

What I am looking for is a clue how to configure this so that the search matches tokens with partial searches, but that only complete tokens are used for the autocomplete feature. Maybe a configuration step is missing?

cn flag
Is your search block created using views with an exposed filter using "Fulltext search" field?
cn flag
Yes, I use a view with a fulltext search filter.
cn flag
You may have to create two indexes and then use this https://www.drupal.org/project/fac on your search input field. This would search the index without ngram for the autocomplete but when you press search/submit it uses the view.
cn flag
Sorry for the lack of feedback. I spent so much frustrating time on this issue, that I needed some time away from it. My current solution is that I have a new field which is a concatenation of all the other fields' contents. This field is the source for the autocomplete. This seems like the right approach, but is not working in practice. I think, I struggle with selecting the right field type for the new field.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.