0

I need to handle suggestion using solr query. Suggestion is working fine. But the problem is that suggestions are conditional i.e. suggestions are based on geo locations. I want the following equivalent query:

q=<SEARCH TERM>&fq=country:"<search country>"

I have tried some approaches but they are not working. What is the way to handle such scenarios?

Edit 1: Suggester Config:

<searchComponent name="suggest" class="solr.SuggestComponent"> 
<lst name="suggester"> 
<str name="name">mySuggester</str> 
<str name="lookupImpl">FuzzyLookupFactory</str> 
<str name="dictionaryImpl">DocumentDictionaryFactory</str> 
<str name="field">autofill</str> 
<str name="contextField">allowed_location</str> 
<str name="suggestAnalyzerFieldType">text_autofill</str> 
<str name="buildOnStartup">false</str> 
<str name="storeDir">path on file system</str> 
</lst> 
</searchComponent>
Mridul Vishal
  • 2,160
  • 4
  • 16
  • 17
  • Have you checked if the country field is indexed in solr? Also, you need the equivalent of the query in which language? Like a java solrj API call? – avinash_inuganti Nov 22 '17 at 03:26
  • yes country is indexed in solr. I am using solr admin console to verify. I believe if i can trigger query using solr console , it can be done in any language. Additional Info: I can get the result using select handler. But the result won't be suggestions. I want to get the result using suggest handler – Mridul Vishal Nov 22 '17 at 03:51
  • kindly show us the code for suggest handler and cou ntry field schema – Dimag Kharab Nov 22 '17 at 07:25

1 Answers1

0

You will have to configure the suggester component in your solrconfig.xml qnd your suggestions queries need to be of the below form(shortened)

suggest.q=<search_term>&suggest.cfq=<search_country>

If you need the filtering query to work on country field, it must be configured as a contextField in your solrconfig.xml

For better understanding please refer to the reference guide link

  • I will try this solution and will discuss after that – Mridul Vishal Nov 22 '17 at 08:46
  • I tried the suggestion and got error. I am using solr 6.6 . It says context is not supported by this suggester – Mridul Vishal Nov 29 '17 at 10:03
  • My suggester config is: mySuggester FuzzyLookupFactory DocumentDictionaryFactory autofill allowed_location text_autofill false path on file system – Mridul Vishal Nov 29 '17 at 10:07
  • suggester stack trace { "error":{ "msg":"this suggester doesn't support contexts", "trace":"java.lang.IllegalArgumentException: this suggester doesn't support contexts\n\tat org.apache.lucene.search.suggest.analyzing.AnalyzingSuggester.build(AnalyzingSuggester.java:404)\n\tat at at , "code":500}} – Mridul Vishal Nov 29 '17 at 10:07
  • field definition for allowed_location – Mridul Vishal Nov 29 '17 at 10:11