Paul Taylor
Paul Taylor

Reputation: 13120

What is the difference between AND and + in Lucene query syntax

So this query

http://jthinkws.elasticbeanstalk.com/?type=release&query=artist:(Dinosaur~0.7 AND Jr.) AND (+track:"Forget The Swan" +track:"Just Like Heaven" ) AND tracks:[2 TO 100] AND src:1&limit=100&offset=0

gives 35 results, whereas

http://jthinkws.elasticbeanstalk.com/?type=release&query=artist:(Dinosaur~0.7 AND Jr.) AND (track:"Forget The Swan" AND track:"Just Like Heaven" ) AND tracks:[2 TO 100] AND src:1&limit=100&offset=0

gives 2 results.

It seems that in the first case it returns documents where the track field matches "Forget the Swan" or "Just Lie Heaven" whereas the second only returns when the track field matches both, so the first query is acting as if there is an implicit OR between the the two track parameters as follows

http://jthinkws.elasticbeanstalk.com/?type=release&query=artist:(Dinosaur~0.7 AND Jr.) AND (+track:"Forget The Swan" OR +track:"Just Like Heaven" ) AND tracks:[2 TO 100] AND src:1&limit=100&offset=0

but if this is so what is the point of the + operator ?

Update: Im now wondering if the issue is related to the fact that the query is made over the internet and whether the '+' is being incorrectly encoded

Upvotes: 3

Views: 581

Answers (1)

femtoRgon
femtoRgon

Reputation: 33351

You are right, about needing to escape the "+" in the URL. As far as Lucene syntax is concerned, x AND y gets interpreted to +x +y by the query parser, so they are identical by definition.

Try replacing the plusses with %2B:

http://jthinkws.elasticbeanstalk.com/?type=release&query=artist:(Dinosaur~0.7%20AND%20Jr.)%20AND%20(%2Btrack:%22Forget%20The%20Swan%22%20%2Btrack:%22Just%20Like%20Heaven%22%20)%20AND%20tracks:[2%20TO%20100]%20AND%20src:1&limit=100&offset=0

Upvotes: 2

Related Questions