Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do NOT IN query in Solr?

Tags:

How can I exclude a set of document IDs from Solr result set? Essentially something like

/select?q=tag_id:367 AND NOT id:(306670,302209)

I tried it and it does not exclude documents with those id's.

like image 797
arun Avatar asked Aug 08 '12 00:08

arun


People also ask

How do you escape special characters in SOLR?

Solr queries require escaping special characters that are part of the query syntax. Special characters are: +, -, &&, ||, !, (, ), ", ~, *, ?, and : . To escape these characters, use a slash ( \ ) before the character to escape.

How do you query in SOLR?

Trying a basic queryThe main query for a solr search is specified via the q parameter. Standard Solr query syntax is the default (registered as the “lucene” query parser). If this is new to you, please check out the Solr Tutorial. Adding debug=query to your request will allow you to see how Solr is parsing your query.

What is DF in Solr query?

The df stands for default field , while the qf stands for query fields . The field defined by the df parameter is used when no fields are mentioned in the query. For example if you are running a query like q=solr and you have df=title the query itself will actually be title:solr .


2 Answers

Try this:

/select?q=*:*&fq=tag_id:367 AND id:[* TO *] -id:(306670 302209)

That should allow you to build out add as many ids as you want without having to add -id:302209 every time you want to eliminate an ID. The reverse is also true, you can swap the - with a + and force an array of values to be there as well.

like image 128
harmstyler Avatar answered Sep 21 '22 21:09

harmstyler


Found one solution:

/select?q=tag_id:367&fq=-id:306670 AND -id:302209

Not sure whether this is the best way to do it though!

like image 27
arun Avatar answered Sep 19 '22 21:09

arun