Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Solr, what is the difference between the NOT and - (minus) operators?

In Solr, is there a difference between the NOT and - (minus) operators? If so, what is it?

Solr documentation references the Lucene Query Parser Syntax, and it is vague on this matter. The two operators seem to function the same way, but it's not clear.

like image 743
Jonathan Tran Avatar asked Jan 06 '11 20:01

Jonathan Tran


People also ask

What is query parser in Solr?

Solr's default Query Parser is also known as the “ lucene ” parser. The key advantage of the standard query parser is that it supports a robust and fairly intuitive syntax allowing you to create a variety of structured queries.

How do you escape in Solr query?

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.

Can Boolean operators like and/or and so on be used in Lucene query syntax?

You can embed Boolean operators in a query string to improve the precision of a match. The full syntax supports text operators in addition to character operators. Always specify text boolean operators (AND, OR, NOT) in all caps.


2 Answers

To expand on Mauricio's answer (because the QueryParser class is some of the most confusing code I've ever read) if you look at lines 145-152 you'll see:

  case MINUS:
    jj_consume_token(MINUS);
             ret = MOD_NOT;
    break;
  case NOT:
    jj_consume_token(NOT);
           ret = MOD_NOT;
    break;

So they are both considered MOD_NOTs.

like image 109
Xodarap Avatar answered Oct 16 '22 11:10

Xodarap


The Lucene QueryParser code says they're equivalent.

like image 41
Mauricio Scheffer Avatar answered Oct 16 '22 11:10

Mauricio Scheffer