|
Created an attachment (id=10276)
Some more unit tests in the "escaped" department This issue was so old that I wanted to verify thatit still exists.
The attached test is specific to the issue and indeed shows that +(fruits vegetables) AND (-tomatoes -bananas) does not perform as expected. I use "QueryParser.setDefaultOperator(QueryParser.OR_OPERATOR)" Doc1 = fruits vegetables tomatoes bananas My expectations is to get docs 2,3,4 - instead the query returns no hits. Somebody please check that this makes sense. I have not run this test with the attached patches applied, however - I decided to not spend the time applying 2 year old patches to the current release Please ignore the previos version - it was very sloppy.
I added one more test, which yields a strange (for me) result: fruits OR -tomatoes returns only: fruits vegetables peppers kiwis but does not return: fruits vegetables tomatoes bananas I would expected all four docs to match? I think the general issue here is that mixing syntax (ie: using AND, OR or NOT along with "+" and "-") is not something that works very well in the QueryParser.
At the lowest level the "+" and "-" syntax most closely models the way Lucene BooleanQueries work – most specificly, they are not truely BooleanQueries – they are agregation queries, in which each sub query can be required, optional or prohibited – but at least one most always "match" and positively select some documents. (it is invalide to have a BooleanQuery containing all "prohibited" clauses) Setting the default operator onthe QueryParser to be "OR" or "AND" really just tells the QueryParser whether you want the default property of the sub-queries to be "optional" or "required" in the absense of other information. when specifying a query like: +(fruits vegetables) AND (-tomatoes -bananas) when specifing a query like: fruits OR -tomatoes in short ... things are behaving as expected. The only question is wether documentation might be improved to make the behavior more clear to people. as for the (now very old) patches to this bug ... they don't acctually seem to be related at all as far as i can tell. This makes sense. Iconcur that docs can be better - maybe we shoud lopen a separate JIRA issue on that?
I propose this to be closed as "will not fix". |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
A patch to queryparser to properly handle escaping char in field