2

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

Paul Taylor
  • 13,411
  • 42
  • 184
  • 351

1 Answers1

2

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

femtoRgon
  • 32,893
  • 7
  • 60
  • 87
  • Right thx that works but I am kind of confused. My original problem was that a query encoded by my server wasn't getting same results as a query put into Firefox browser and encoded by Firefox. I asumed my code was wrong but now seems that Firefox was wrong - comments http://stackoverflow.com/questions/33476604/what-is-the-reason-for-the-difference-between-these-two-urlencodings-of-url – Paul Taylor Nov 02 '15 at 16:55
  • @PaulTaylor - I wouldn't say that Firefox was wrong, really. Unfortunately, Firefox is not equipped with mind-reading technology (yet), so it can't be expected to know that *this* plus was supposed to be a literal plus, instead of the usual escaped space. [See more on how the plus symbol is handled in urls here](http://stackoverflow.com/questions/1005676/urls-and-plus-signs). – femtoRgon Nov 02 '15 at 17:11
  • right gotcha so really I was wrong to use Firefox as a benchmark to compare my queries, (it seems it just the plus sign that was causing me problems) – Paul Taylor Nov 02 '15 at 17:42