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

后端 未结 3 1851
离开以前
离开以前 2021-01-30 12:12

I\'ve looked through a ton of examples and other questions here and from them, I\'ve got my config very close to what I need but I\'m missing one last little bit that I\'m havin

相关标签:
3条回答
  • 2021-01-30 12:19

    I've tried this many times and I came to the conclusion that is not possible out of the box. I found a workaround for that:

    I indexed the data adding sopecial chars between each word so that they would not be tokenized. For example:

    solarzzzzzzpowered
    solarzzzzzzglass
    solarzzzzzzglobe
    

    then when you compose your query you make sure you add the same amount of chars between the two words you type, for example solr gl become solarzzzzzzgl.

    This will achieve the behavious that you are asking.

    Another option would be not to use the autosuggestion field and make a custom field for yourself, but then you will have to manage the wildcard search and all the indexation by yourself and is not too convenient in terms of time and performance.

    0 讨论(0)
  • 2021-01-30 12:27

    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
    
    0 讨论(0)
  • 2021-01-30 12:28

    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>
    
    0 讨论(0)
提交回复
热议问题