문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top