Question

I have a problem. I have 3 filters in solr. Lets call them filter A, B and C. My requirement is that I want filter A to be mandatory and B and C to be optional. If I write and '&' between the filter then all 3 will become mandatory.

http://127.0.0.1:8983/solr/core1/select?q=*:*&fq=A:a_value&fq=B:b_value&fq=C:c_value&wt=xml&indent=true

A use or 'OR' in between them makes the filter 'A' non mandatory.

http://127.0.0.1:8983/solr/core1/select?q=*:*&fq=A:a_value or B:b_value or C:c_value&wt=xml&indent=true

How should I handle this situation

Était-ce utile?

La solution

If I understand your question correctly, you want to be certain your documents match filter A and match filter B or C.

If this is the case you can use the following filter query

fq=(A:a_value AND (B:b_value OR C:c_value))

Be sure your AND's and OR's are capitalized.

Autres conseils

If B and C are optional why you're using FQ?

FQ (filter query) is useful when you actually filtering and you need to remember that it will not be counted into the score.

So 1. You actually would like to use it in Q (that way when doc match B/C it will be reflected in the score) Or 2. If B/C should not influence score, why you are putting it in at all?

In case 1 query could look like:

(A:a_value AND ((B:b_value OR -B:b_value) OR (C:c_value OR -C:c_value)))

You might need to adjust *-B:b_value* because I'm not 100% sure

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top