What happened to this solr range filter request?

The following filter query returns null results (using *: * as the query):

-startDate:[* TO *] OR startDate:[* TO NOW/DAY+1DAY] 

But if I filter only:

 -startDate:[* TO *] 

I get 3 results.

If I filter only:

 startDate:[* TO NOW/DAY+1DAY] 

I get 161 results.

Why does combined FQ return null results? I want the filter to return any document whose start date is zero or the start date until today.

EDIT:

I am using Solr 4.2.1.2013.03.26.08.26.55

EDIT:

Well, strange, it can happen that a colleague suggested putting parentheses in two parts as follows:

 (-startDate:[* TO *]) OR (startDate:[* TO NOW/DAY+1DAY]) 

And somehow it worked. I'm still wondering why this made a difference. Hope someone can shed some light.

Thanks!

+6
source share
4 answers

Solr supports purely negative requests. They do this essentially by expanding the net negative to something like:

 *:* -startDate:[* TO *] 

However, what you combine in BooleanQuery, I do not believe that it applies such logic. A negative query in lucene does not receive anything, but rather filters out matches caused by other, positive, query conditions. This is different from SQL queries, which in a sense begin with an implicit *:* or a full table of results and allow you to bypass it.

I believe that your OR effectively ignored, since, strictly speaking, it does not make sense in the context. Typically, OR is just syntactic sugar, I think ( field:this OR field:that equivalent to field:this field:that ).

So, actually your query is: startDate:[* TO NOW/DAY+1DAY] -startDate:[* TO *] , which makes the results more obvious. When you wrap it in parentheses, each terminological request is processed separately, and you get access to solr support for lone negative requests.


It is much better to remember storing the default value if you need to look for unset / null values. *:* , and as a result, pure negative queries like this should scan the entire index, and therefore run very poorly. Providing a default value will improve performance and prevent this confusing situation.

+6
source

I used the femtoRgon answer and was able to build a query including a range and empty values.

Listed below are all documents with StartDate starting January 1, 2012, and all documents without StartDate.

 (StartDate:[2014-01-01T00:00:00Z TO *]) OR (-StartDate:([* TO *]) AND *:*) 

Magic (-StartDate:([* TO *]) AND *:*) . This will select documents without StartDate.

0
source

Pure negative queries do not work because they lose nothing.

Try:

: AND -startDate: [* TO *]

-1
source

When you query with -startDate:[* TO *] , you get documents that don't have data for the startDate field.

When you request startDate:[* TO NOW/DAY+1DAY] , you receive documents whose values ​​are less than or equal to NOW/DAY+1DAY in the startDate field.

You can try -startDate:* OR startDate:[* TO NOW/DAY+1DAY] . The first part indicates documents that do not matter, and the second part says that the document has a value less than or equal to NOW/DAY+1DAY in the startDate field.

-1
source

Source: https://habr.com/ru/post/947776/


All Articles