问题
I am using apache solr to search records in my current application.
And I was able to filter the suggesions based on DocumentType by configuring the context field.
Now I want to add another context field like departmentType. I am not sure how to configure the suggester for multiple context fields.
This is the suggester that used with single context fields and this is working fine.
<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">suggesterByName</str>
<str name="lookupImpl">AnalyzingInfixLookupFactory</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="field">fullName</str>
<str name="contextField">documentType</str>
<str name="suggestAnalyzerFieldType">text_general</str>
<str name="buildOnStartup">false</str>
</lst>
</searchComponent>
I refer this post https://issues.apache.org/jira/browse/SOLR-7888
but still not clear how to configure multiple context fields in a single suggester .
回答1:
You have to create a new field in your schema.xml as context_field.
This field should have multivalued=true
<field name="context_field" type="text_suggest" multiValued="true" indexed="true" stored="true"/>
Then you have to create this context_field as a list in json for indexing in solr.
"context_field" : ["some document type", "some department type"]
after indexing you can suggest like this-
suggest.q=b&suggest.cfq=context_documentType AND context_departmentType
Hope it works
来源:https://stackoverflow.com/questions/36079395/how-to-configure-multiple-contextfields-in-single-solr-suggester