Search code examples
solrsolrj

solr query for not equal to text value and number greater than 0


I have solr documents with two fields, one is a string and one is an integer. Both fields are allowed to be null. I am attempting to write a query that will eliminate documents with the following properties:

textField = "badValue" AND (numberField is null OR numberField = 0)

I added the following fq:

((NOT textField=badValue) OR numberField=[1 TO *])

This does not seem to have worked properly, because I am getting a document with textField = badValue and numberField = 0. What did I do wrong with my fq?

The full query response header, containing the parsed query is:

"responseHeader": { "status": 0, "QTime": 245, "params": { "q": "(numi) AND (solr_specs:[* TO ] OR full_description:[ TO ])", "defType": "edismax", "bf": "log(sum(popularity,1))", "indent": "true", "qf": "categories^3.0 manufacturer^1.0 sku^0.2 split_sku^0.2 upc^1.0 invoice_description^2.6 full_description solr_specs^0.8 solr_spec_values^1.7 legacyid legacy_altcode id", "fl": "distributor_status,QOH_estimate,id,score", "start": "0", "fq": "((:* NOT distributor_status=VENDORDISC) OR QOH_estimate=[1 TO *])", "sort": "score desc,id desc", "rows": "20", "wt": "json", "_": "1441220051438" } }

QOH_estimate is numberField and distributor_status is textField.


Solution

  • Please try the following in your fq parameter: ((*:* NOT textField:badValue) OR numberField:[1 TO *]).

    ((*:* NOT distributor_status:VENDORDISC) OR QOH_estimate:[1 TO *])

    Here you first selecting the documents which are not containing textField:badValue and ORing with documents coming from numberField:[1 TO *] condition.