Solr filter query including NOT and OR

13,864

The negation needs a complete set to match against it, so your filter should be:

fq=((*:* AND -type_id:A) OR content:(['' TO *]))
Share:
13,864
Kimberly
Author by

Kimberly

I'm a mid-level full-stack developer, with most of my experience in the Microsoft stack (C#, .NET, WCF, ASP.NET, SQL Server). I recently returned from a sabbatical of travel, work exchange, and volunteering.

Updated on June 05, 2022

Comments

  • Kimberly
    Kimberly almost 2 years

    For a filter query in Solr, I need to include all documents not of a certain type, plus any documents of that type which have a value in a certain field.

    I tried this:

    fq=(-type_id:(A) OR content:(['' TO *]))
    

    But it is excluding documents of type_id B, C, etc. which have null content. (type_id is a string field and content is text.)

    I have seen this question: Complex SOLR query including NOT and OR and this post about operators: http://robotlibrarian.billdueber.com/2011/12/solr-and-boolean-operators/. I think the syntax I have should be correct. Can anyone see my error?


    Update: I am using the LuceneQParser. It parses the filter query above as

    -type_id:A content:['' TO *]
    

    It parses the filter query suggested in the comments (-type_id:A OR (content:[* TO *] AND type_id:A)) as

    -type_id:A (+content:[* TO *] +type_id:A)
    

    so no results.