springsolrcriteriaspring-data-solr

Is there any way to apply De Morgan's law to dynamic query in Spring Data Solr?


I've got the following problem:

Solr seems to not like and return anything when a part of my dynamically generated criteria contains only negations, like this:

 AND (-title_facet:*title* AND -title_facet:*List*)

(Which is a Crotch, created from two separate Criteria)

As this really makes a problem, is there any way to apply De Morgan's law to said criteria so it would be:

AND -(title_facet:*title* OR title_facet:*List*)

?

I'm using Spring-data-solr 1.5.4


Solution

  • The reason why AND (-title_facet:*title* AND -title_facet:*List*) doesn't work, is because it doesn't have anything to subtract the matching documents from.

    Solr works around this when you use it as a single query by appending the set of all documents in front of your query, but when you're doing the same thing further into a query, that won't be present.

    AND (*:* AND -title_facet:*title* AND -title_facet:*List*)
    

    .. should work, since you then have a proper set of documents (all the documents) which you can subtract those matching the other two sets from.