TAGS :Viewed: 11 - Published at: a few seconds ago

[ how to filter search by values that are not available ]

I have a list of items as:

i = SearchQuerySet().models(Item)

now, each item in i has a attribute, price

I want to narrow the result in which price information is not available along with the ones falling in a given range

something like

i.narrow('price:( None OR [300 TO 400 ] )')

how can that be done?

Answer 1

As per the SolrQuerySyntax

Pure Negative Queries :-

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

You can try :- q=(*:* -price:[* TO *]) OR price:[300 TO 400]

Answer 2

Try this:

-(-price:[300 TO 400] AND price:[* TO *])

is logically the same and it works in Solr.

Answer 3

One can use a filter query if you do not care about the document score and want to leverage the filter cache, like:

?q=*:*&fq=((-price:[* TO *]) or (price:[300 TO 400]))