3

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 .

  • Did you find an answer to this ? I've similar requirements, looks like SOLR-7888 supports multiple values for a given context field using boolean query. – Shamik Jun 22 '16 at 18:08

1 Answers1

6

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

vsri293
  • 541
  • 4
  • 7
  • do you know if it is possible to return the suggestions grouped by context fields? – Fabrizio Fortino Aug 05 '16 at 11:19
  • @FabrizioFortino can you please explain 'grouped by context fields'?? – vsri293 Aug 05 '16 at 11:40
  • Context filtering lets you filter the suggestions with a separate context field. Is there any way to return the suggestions grouped by the context field? For example, I have these docs: `{name: aaaa, suggest: mercedes, type: car}, {name: bbbb, suggest: mazda, type: car}, {name: cccc, suggest: mazda, type: car}, {name: dddd, suggest: mercedes, type: bike}` Let's say the user types "m", I would like to get back `{suggest: mazda, type: car, count: 2}, {suggest: mercedes, type: car, count: 1}, {suggest: mercedes, type: bike, count: 1}` – Fabrizio Fortino Aug 05 '16 at 13:52
  • 1
    if you are using solr's inbuilt auto-suggester, i don't think there is any direct way to get group result by context field, but there is facet query in solr may be you can use that. [facet query example](https://examples.javacodegeeks.com/enterprise-java/apache-solr/solr-faceted-search-example/) – vsri293 Aug 08 '16 at 11:29