Skip to main content
3 of 3
Updated and highlighted the description
Sumit Bhatia
  • 5.9k
  • 2
  • 9
  • 25

Solr auto suggest from multiple fields

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);
        }
Jey
  • 373
  • 2
  • 16