How to have Solr autocomplete on whole phrase when query contains multiple terms?

You may use the AnalyzingInfixLookupFactory or FreeTextLookupFactory

  • AnalyzingInfixLookupFactory returns the entire content of the field.
  • FreeTextLookupFactory returns a defined number of tokens.

More details and other suggester algorithms you will find here: http://alexbenedetti.blogspot.de/2015/07/solr-you-complete-me.html

Solr Configuration

<lst name="suggester">
  <str name="name">AnalyzingInfixSuggester</str>
  <str name="lookupImpl">AnalyzingInfixLookupFactory</str> 
  <str name="dictionaryImpl">DocumentDictionaryFactory</str>
  <str name="field">title</str>
  <str name="weightField">price</str>
  <str name="suggestAnalyzerFieldType">text_en</str>
</lst>

<lst name="suggester">
  <str name="name">FreeTextSuggester</str>
  <str name="lookupImpl">FreeTextLookupFactory</str> 
  <str name="dictionaryImpl">DocumentDictionaryFactory</str>
  <str name="field">title</str>
  <str name="ngrams">3</str>
  <str name="separator"> </str>
  <str name="suggestFreeTextAnalyzerFieldType">text_general</str>
</lst>

Found the answer, finally! I knew I was really close. Turns out my configuration above was correct and I simply needed to change my query.

  1. Use KeywordTokenizerFactory so that the strings get indexed as a whole.
  2. Use SpellCheckComponent for the request handler.
  3. The piece I was missing -- don't query with q=<string> but with spellcheck.q=<string>.

Given the source strings noted above and a query of spellcheck.q=solar+gl this yields the desired results:

solar glass
solar globe

Tags:

Solr