Is it possible to do Algebraic Operations in Solr Result set?

106 views Asked by At

Currently I am firing 3 Solr queries and doing operations in my servlet to achieve my requirement. My requirement is finding words that belong to non special category.

Special category words will have entries in special documents as well as normal documents, there will be two special categories. So I need to extract all the documents and remove the special categories from that. Currently I am doing that in servlet using Hash Maps.

Is it possible to do that in a Solr query without writing any handlers?

I wanted to achieve something like query1 - (query2 U query3)

1

There are 1 answers

4
cheffe On

You can use filter queries to exclude results of other queries from the original query. In Solr you can negate a query result using -. This will not cover all possible Set Operations, but it should suffice for your needs.

To give an example, assumed you query for T-Shirts of a certain company

q=company:hilfiger

Now you want to exclude those Shirts which are red or green. To do that you negate each query with a - and you would add a separate fq parameter for each constraint.

fq=-color:red&fq=-color:green

Putting all that together you would query for

`q=company:hilfiger&fq=-color:red&fq=-color:green

References about filter queries