1

I am trying to Solr auto suggest query from multiple fields (say for example, name_t, description_t) in a single request handler or same suggest.dictionary.

I have the configs as below, when I have multiple "field" under the same suggester, it's not working. Also, when I try with the same name that's also not working.

<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">NameSuggester</str>
<str name="lookupImpl">FSTLookupFactory</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="field">name_t</str>    
<str name="suggestAnalyzerFieldType">string</str>
</lst>  
<lst name="suggester">
<str name="name">DescriptionSuggester</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="lookupImpl">FSTLookupFactory</str>   
<str name="field">description_t</str>            
<str name="suggestAnalyzerFieldType">string</str>
</lst>  
</searchComponent>

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

C# Code

 using (var ctx = ContentSearchManager.GetIndex("sitecore_master_index").CreateSearchContext())
        {
            SolrSuggestQuery q = "Description";
            var options = new SuggestHandlerQueryOptions
            {
                Parameters = new SuggestParameters
                {
                    Count = 10,
                    Build = true
                }
            };

            var result = ctx.Suggest(q, options);
            var resultnew = result.Suggestions["DescriptionSuggester"].Suggestions.Select(a => a.Term);
        }

2 Answers 2

1

It looks like related to configuration only. You can try changing your configuration a bit like use AnalyzingInfixLookupFactory in lookupImpl and also removes dictionaryImpl.

<searchComponent name="suggest" class="solr.SuggestComponent">
     <lst name="suggester">
       <str name="name">mySuggester</str>
       <str name="lookupImpl">AnalyzingInfixLookupFactory</str>
       <str name="field">autocomplete__txtsug</str>
       <str name="suggestAnalyzerFieldType">string</str>
       <str name="buildOnStartup">true</str>
     </lst>
</searchComponent>

Also, Add the new field in Managed-Schema file.

<fieldType class="solr.TextField" name="textSuggest" positionIncrementGap="100">
   <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
   </analyzer>
</fieldType>

Refer to this for step-by-step details: Enabling the Suggester from SOLR for the Search box

Updated

Use copyfields to combine multiple fields into a single field and use that field as a suggester.

schema:

<copyField source="name" dest="mynewfield" />
<copyField source="other_name" dest="mynewfield" />

suggester:

<str name="field">mynewfield</str>

Hope it helps!

9
0

Adding one more thing with the configuration you have already done with. You can try rebuilding your suggested like below.

http://localhost:8983/solr/index_name/suggest?suggest.build=true

Until you do this step, no suggestions are returned.

After completing this ask for suggestions like below.

http://localhost:8983/solr/index_name/suggest?suggest.q=whatever

The response will contain a suggest field. This field will contain fields for each of the suggest.dictionaries that was used. Each of these dictionary fields will have a "numFound" field as well as a "suggestions" field containing an array of the found suggestions.

Hope this will help.

1
  • Hi Sumit, Thanks, i was facing a config issue to copy more than one source field to one destination field. This works now. But the suggestion is suggesting based on the first or prefix of the value from the particular configured field. when i pass any word other than the first, it's not yielding any result.
    – Jey
    Commented Apr 17, 2023 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.