1

I'm having a problem using Solr's suggest component, the implementation class that I want to use is AnalyzingInfixLookupFactory, I'm using this to get suggestions based on infix not only the prefix. Also I needed Solr to see the search term as one token. but the problem is that the Solr always returns suggestions based on the prefix not the infix.

my Suggest component in solrconfig.xml:

  <searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
  <str name="name">mySuggester</str>
  <str name="lookupImpl">AnalyzingInfixLookupFactory</str>      <!-- org.apache.solr.spelling.suggest.fst -->
  <str name="dictionaryImpl">DocumentDictionaryFactory</str>     <!-- org.apache.solr.spelling.suggest.HighFrequencyDictionaryFactory --> 
  <str name="field">movie_name</str>
  <str name="weightField">movie_meter</str>
  <str name="buildOnCommit">true</str>
  <str name="suggestAnalyzerFieldType">text_general</str>
</lst>

the text_general in schema.xml:

  <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
  <analyzer type="index">
    <tokenizer class="solr.KeywordTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.KeywordTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>   
  </analyzer>
</fieldType>
Phuc Thai
  • 718
  • 7
  • 17
Ahmed
  • 49
  • 2
  • 9

2 Answers2

5

I know this was asked a long while ago, but here's my answer anyway.

Use the following analyzer field types in the above solrconfig.xml:

<str name="suggestAnalyzerFieldType">text</str>
<str name="queryAnalyzerFieldType">text_suggest</str>

Then in schema.xml:

<fieldtype name="text" class="solr.TextField">
  <analyzer>
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldtype>

<fieldtype name="text_suggest" class="solr.TextField">
      <analyzer>
        <tokenizer class="solr.KeywordTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.TrimFilterFactory"/>
      </analyzer>
    </fieldtype>
  • Hi James, why do we need to add the text and text_suggest in the solrconfig.xml. I have tried an example and without adding in solrconfig.xml it is working. Do I missing something? – Narendra Jaggi Nov 07 '17 at 10:44
  • Hi Nerandra, the suggestAnalyzerFieldType is using the StandardTokenizerFactory so that text can be entered using any of the terms in the field. The queryAnalyzerFieldType uses the KeywordTokenizerFactory so that the whole field is returned as a string. This is useful in short suggestion fields, such as authors, titles, etc. (If you begin typing in amadeus, it will return wolfgang amadeus mozart, for example) – James Doepp - pihentagyu Nov 07 '17 at 16:02
  • This also works with spaces, so if you type "amadeus mo" or even "amadeus wo" it will still return "wolfgang amadeus mozart" – James Doepp - pihentagyu Nov 07 '17 at 19:02
3

For Solr Version 6.6.
Its been a little late but it will be useful to other people. I want to configure the search for the field "product_name".
solrconfig.xml

<searchComponent name="suggest" class="solr.SuggestComponent">
      <lst name="suggester">
        <str name="name">productSuggester</str>
        <!--<str name="lookupImpl">FuzzyLookupFactory</str> -->
        <str name="lookupImpl">AnalyzingInfixLookupFactory</str> -->
        <str name="dictionaryImpl">DocumentDictionaryFactory</str>
        <str name="field">product_name</str>
        <!-- <str name="weightField">price</str> -->
         <str name="buildOnCommit">true</str>
        <str name="suggestAnalyzerFieldType">text_suggest</str>
        <str name="buildOnStartup">true</str>
        <str name="highlight">false</str>
      </lst>
    </searchComponent>

managed-schema

<fieldtype name="text_suggest" class="solr.TextField">
      <analyzer>
        <tokenizer class="solr.StandardTokenizerFactory"/>           
        <filter class="solr.LowerCaseFilterFactory" />
        <filter class="solr.ASCIIFoldingFilterFactory"/>
    </analyzer>
 </fieldtype>

<field name="product_name" type="text_suggest" />
Narendra Jaggi
  • 1,297
  • 11
  • 33