Socratees Samipillai
Socratees Samipillai

Reputation: 3105

Behavior of the OR clause in Solr

My solr index contains documents which have a field named department. This field is a multivalue non-required int field. I want to construct a query whose result must be union of

I tried constructing the query that looks like so:

-department:* OR (department:* AND department:(100 OR 200))

This doesn't return any results. Whereas if I just just use

-department:* 

or

department:* AND department:(100 OR 200)

, the query seems to work well. In short I'm having trouble understanding the behavior of OR clause in this context. Any pointers?

Upvotes: 0

Views: 691

Answers (2)

Mavellin
Mavellin

Reputation: 665

To achieve what you want, I think you can use Solr grouping.

You can give something like,

&q=*&group=true&group.query=department:[100]&group.query=department:[200]&group.query=-department:[*]

Upvotes: 0

Jayendra
Jayendra

Reputation: 52779

Checkout SolrQuerySyntax

Pure Negative Queries :-

-field:[* TO *] finds all documents without a value for field

You can try :-

q=-department:[* TO *] OR department:(100 OR 200)

Upvotes: 2

Related Questions