user3407386
user3407386

Reputation: 172

Solr "+" or required operator

I am searching in solr(5.1) using 3 terms and I get different results when I change the order of terms. When I used debugQuery from solr I found that,solr is adding +(required operator) when the operator between terms is AND.

Example:-

I have 4 documents with field as name. The default operator is OR

"docs": [ { "name": "The Lightning Thief" }, { "name": "The Sea of Monsters" }, { "name": "Sophie's World : The Greek Philosophers" }, { "name": "Lucene in Action, Second Edition" } ]

Query1 = name:("The Sea of Monsters" NOT "Lucene in Action, Second Edition" AND "The Lightning Thief")

Result = "name": "The Lightning Thief"

"parsedquery": "name:The Sea of Monsters -name:Lucene in Action, Second Edition +name:The Lightning Thief"

Query 2 = name:("The Sea of Monsters" AND "The Lightning Thief" NOT "Lucene in Action, Second Edition")

Results = 0 documents found

"parsedquery": "+name:The Sea of Monsters +name:The Lightning Thief -name:Lucene in Action, Second Edition""

Please help me understand this logic.

Upvotes: 0

Views: 260

Answers (2)

Manu Eidenberger
Manu Eidenberger

Reputation: 2096

The problem certainly comes from your default operator (AND vs OR). Can you provide exact queries and debug output ?

Also, Try to activate edismax in your query like following, so you can use negations.

http://localhost:8983/solr/your_search_core/select?defType=edismax&q=(term1+OR+term2)+AND+-term3

Upvotes: 0

David George
David George

Reputation: 3752

If your default operator is OR this is what I would expect. Your second example is

TERM1 (OR) NOT TERM2 AND TERM3

So TERM1 is optional

Upvotes: 1

Related Questions