Reputation: 21
I am using Apache Solr Suggester for Auto-complete. When I search with 'DC' I get the response DC-UK_ITP along with other values.
When I search DC-UK_ITP, it is not able to find the value and returns no suggestions.
How should I pass the value DC-UK_ITP so that it is able to find the value correctly?
Or is there any settings I need to do at Solr configuration.
Upvotes: 1
Views: 1151
Reputation: 1042
When configuring the "suggester" component it is always important to keep an eye on "suggestAnalyzerFieldType" parameter from solrconfig.xml
<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">mySuggester</str>
...
<str name="suggestAnalyzerFieldType">suggest_type</str>
...
</lst>
</searchComponent>
Values which were produced at "index-time" (when suggester built its data structures) should correspond and match the values which will be obtained at "query-time" (essentially when you will issue the query).
Considering you have following set-up in schema.xml:
<field name="suggest_field" type="suggest_type" indexed="true" stored="true" multiValued="true"/>
<fieldType name="suggest_type" class="solr.TextField">
<analyzer>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.TrimFilterFactory" />
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
</fieldType>
Document with
"suggest_field": ["DC-UK_ITP"]will be stored in indices with the following terms: dc, uk_itp.
In order to have "contains"-based suggester I would recommend considering the AnalyzingInfixLookupFactory lookup as follows:
<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">infixSuggester</str>
<str name="lookupImpl">AnalyzingInfixLookupFactory</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="field">suggest_field</str>
<str name="weightField">price</str>
<str name="suggestAnalyzerFieldType">suggest_type</str>
<str name="buildOnStartup">false</str>
</lst>
</searchComponent>
Analyzing Infix Lookup will also bring you highlight in the response, which is very handy if you are using it directly from the search-box UI. Matching strategy will allow you to match by any prefix, so you'll be able to match original "DC-UK_ITP" value either by:
Useful resources on the topic:
Upvotes: 1
Reputation: 137
"Suggester" simply retrieves tokens starting with characters "DC" from a token dictionary corresponding to an indexed field, in this case it retrieves token "DC-UK_ITP". You then make a query to another field, indexed differently, and you use "DC-UK_ITP" as a search term, and this another term dictionary (corresponding to another field) doesn't contain it.
Upvotes: 0