1

I want to do a Apache Solr search that will do the following:

If field=value1 returns anything then return that.

Else if field=value2 returns anything then return that.

Else field=value3 returns anything then return that.

How can I do that? Any help? Currently I am writing if else logic in java.

Sumit
  • 856
  • 5
  • 18
  • 38
  • What do you mean by return 'anything'? You mean that field exists (has any value associated with it)? Or that field has specific values (value1, value2, etc)? – eribeiro Aug 20 '18 at 21:48
  • Means whether the query returns an data in result or not. If the result count =0 then fire the next one. – Sumit Aug 21 '18 at 09:03
  • Suppose that you have two fields: field1 and field2. If you use this in the fl: `value:if(field1, field1, if(field2, field2, ''))` where `value` is an alias then it will test if the field1 exists and return it or else if field2 exists and return it, so on. Does it solve your problem? ps: You could upload an snippet of your Java code so that we can have an unambiguous of what you are trying to accomplish with pure Solr queries... – eribeiro Aug 21 '18 at 20:21

1 Answers1

0

You can use group query. First do filter query with (field:value1 OR field:value2 OR field:value3) and then specify group.query=field:value1&group.query=field:value2&group.query=field:value3. Now solr will return grouped results which you can choose from.

You will still have to use if else or some other logic to get desired valued group but you will get results in single solr query.

Solr Group Query Resource.

https://lucene.apache.org/solr/guide/6_6/result-grouping.html

PS - I am assuming here you already have value1,value2 and value3.

raghu777
  • 319
  • 2
  • 11