Pregunta

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>
¿Fue útil?

Solución

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>

Otros consejos

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" />
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top