Reputation: 77
I have following problem: I have one Solr core with multiple indexes. I have for example 3 different search types on my website:
I have autosuggest for Nr.3. 1 and 2 have no suggester so far. But I would like to implement an additional suggester for cars, so that when I would like to search only in cars, suggester will show me words only belonging to cars and not to dvds etc. I was thinking about new requestHandler and executing search, because I need for these two specific fields to fill suggestions where Nr.3 search is filled automatically through dictionary. Is it possible to have two or more different suggesters in one Solr Core? And how can I use specific fields for a certain search type for autocomplete and suggestions, so that only cars attributes are listed in these suggestions?
Upvotes: 2
Views: 2203
Reputation: 1308
Sure, that can be done. Just set up two search components something like this:
<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">suggest_cars</str>
<str name="lookupImpl">BlendedInfixLookupFactory</str>
<str name="blenderType">linear</str>
<str name="dictionaryimpl">DocumentDictionaryFactory</str>
<str name="field">cars_suggest</str>
<str name="weightField">popularity</str>
<str name="suggestAnalyzerFieldType">text_suggest</str>
<str name="queryAnalyzerFieldType">phrase_suggest</str>
<str name="indexPath">cars_suggest</str>
<str name="buildOnStartup">false</str>
<str name="buildOnCommit">false</str>
<bool name="exactMatchFirst">true</bool>
</lst>
<lst name="suggester">
<str name="name">suggest_all</str>
<str name="lookupImpl">BlendedInfixLookupFactory</str>
<str name="blenderType">linear</str>
<str name="dictionaryimpl">DocumentDictionaryFactory</str>
<str name="field">suggest</str>
<str name="weightField">popularity</str>
<str name="suggestAnalyzerFieldType">text_suggest</str>
<str name="queryAnalyzerFieldType">phrase_suggest</str>
<str name="indexPath">all_suggest</str>
<str name="buildOnStartup">false</str>
<str name="buildOnCommit">false</str>
<bool name="exactMatchFirst">true</bool>
</lst>
Then create a request handler:
<requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="echoParams">all</str>
<str name="wt">json</str>
<str name="indent">false</str>
<str name="suggest">true</str>
<str name="suggest.count">10</str>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>
In the schema.xml file, these two field types:
<fieldType name="phrase_suggest" class="solr.TextField" positionIncrementGap="100">
<analyzer>
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.TrimFilterFactory"/>
</analyzer>
</fieldType>
<fieldType name="text_suggest" class="solr.TextField" positionIncrementGap="100">
<analyzer>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.ASCIIFoldingFilterFactory"/>
<filter class="solr.EnglishPossessiveFilterFactory"/>
</analyzer>
</fieldType>
And of course you need the two fields cars_suggest and all_suggest containing suggest terms for cars and cars/dvds respectively, with field type phrase_suggest (i.e. with a keyword tokenizer).
The query is done as follows:
http://localhost:8983/solr/collection0/suggest?q=peug&suggest.dictionary=suggest_cars
Upvotes: 5