Friday, July 27, 2018

is Lucene + classic query search syntax same as using AND

Leave a Comment

A Lucene query of the form

field1:+"term1" field2:+"term2" 

seems to be equivalent to

field1:"term1" OR field2:"term2" 

I expected it to be equivalent to

field1:"term1" AND field2:"term2" 

(i.e for my particular query on my database query 1 and 2 are returning 10 records, whereas query 3 is returning 6 records, I would expect query 2 to only return six records)

Im aware that if there is no OR or AND it defaults to OR but I thought the + means that term has to match, otherwise what is the point of the + What am i misunderstanding ?

1 Answers

Answers 1

That query doesn't look equivalent to either of those, to me.

field1:+"term1" field2:+"term2" 

Is just invalid syntax, and the standard QueryParser does kick out a ParseException for it (maybe your code is swallowing the exception silently or something?).

It should be:

+field1:"term1" +field2:"term2" 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment