Search code examples
solrsolrnet

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

  • All the documents that do not contain the field department
  • All the documents that contain the field department, but the values of the field are restricted to a selected few.

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?


Solution

  • 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)