2

I am trying to implement auto suggest feature using Solr 6.6 and Spring Boot on the product_name field. I am giving following records in the core.

{"id":"xsku2023","type":"0","name":"Retro Lamp","product_id":"xprod2023","product_name":"Bajaj Lamp","product_type":"null","product_description":"Cheap and Best Lamp","listPrices":"65","plist3080002":"39.99","inventory_status":"In Stock","category_id":"catTableLamps","category_name":"TableLamps","category_href":"null","category_parent":"null","brand":"Bajaj"},

{"id":"xsku2024","type":"0","name":"Retro Lamp","product_id":"xprod2024","product_name":"Bajaj Table Lamp","product_type":"null","product_description":"Cheap and Best Table Lamp","listPrices":"65","plist3080002":"39.99","inventory_status":"In Stock","category_id":"catTableLamps","category_name":"TableLamps","category_href":"null","category_parent":"null","brand":"Bajaj"}

I have defined the /suggest endpoint as defined here and is working

I am able to achieve the basic suggest feature.

http://localhost:8983/solr/ProductATG/suggest?suggest=true&suggest.build=true&suggest.dictionary=productSuggester&wt=json&suggest.q=Baj


Getting the below response, when hitting the above URL,which is perfectly fine and I am getting the product name starting with prefix I provided in query.

{"responseHeader":{"status":0,"QTime":8},"command":"build","suggest":{"productSuggester":{"Baj":{"numFound":2,"suggestions":[{"term":"Bajaj Lamp","weight":0,"payload":""},{"term":"Bajaj Table Lamp","weight":0,"payload":""}]}}}}


Now, I want to go next level and want to achieve the result, irrespective of order. For ex.

Product name avilable in Solr index - "Bajaj Lamp", "Bajaj Table Lamp"

If I search for Lamp , both product name "Bajaj Lamp", "Bajaj Table Lamp" should come in response currently if I search Lamp no results are found is coming.

Narendra Jaggi
  • 1,297
  • 11
  • 33

1 Answers1

0

I have figured it out how to do the unordered search. This can be achieved by using the AnalyzingInfixLookupFactory. AnalyzingInfixLookupFactory can do the infix search.

solrconfig.xml

<requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy">
  <lst name="defaults">
    <str name="suggest">true</str>
    <str name="suggest.count">10</str>
  </lst>
  <arr name="components">
    <str>suggest</str>
  </arr>
</requestHandler>



<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>

<!-- Added for testign AnalyzingInfixLookupFactory -->
<str name="queryAnalyzerFieldType">text_suggest</str>

managed-schema

 <fieldtype name="text_suggest" class="solr.TextField">
      <analyzer>
        <tokenizer class="solr.StandardTokenizerFactory"/>           
        <filter class="solr.LowerCaseFilterFactory" />
        <filter class="solr.ASCIIFoldingFilterFactory"/>
      </analyzer>
 </fieldtype>
Narendra Jaggi
  • 1,297
  • 11
  • 33