GNOME Bugzilla – Bug 538203
Incorrect parsing of search terms involving "-"
Last modified: 2008-07-15 12:50:10 UTC
Please describe the problem: When a search filter such as "term1 -term2" is used, the result is as predicted, which is to include all entries which match "term1", and exclude all entries which match "term2". However, reversing the search filter to "-term2 term1" doesn't give the same result. Instead, the result is rather unpredictable. An example is "cascada -ready" and "-ready cascada". The former results in all Cascada songs appearing except "Ready For Love", whereas the latter results in just "Ready For Love" by Cascada appearing. Steps to reproduce: 1. Open a media source 2. Type two terms, one preceded by a not operator. 3. Reverse the two terms 4. Observe the different results. Actual results: Incorrect parsing of the search terms for "-term2 term1". Expected results: "-term2 term1" should be identical to "term1 -term2". Does this happen every time? Yes Other information:
I can reproduce this bug. Performing a search on "-term2 term1" yields all titles containing both term1 and term2. Searching for "-term2" however works as expected, only after entering the second search term, titles matching term2 appear. I am attaching an excerpt from an sql log showing the generated queries for searching "term1 -term2" and "-term2 term1".
Created attachment 114083 [details] Log of performed SQL queries SQL queries when searching for "term1 -term2" and "-term2 term1"
Created attachment 114102 [details] [review] proposed fix This patch to UserQueryParser.cs appears to fix the bug. If ParseToken was called to parse an 'And' or 'Or' token while current_parent was pointing to a 'Not' node, it simply forgot to include this 'Not' node into the resulting parse tree. This patch makes ParseToken handle this case separately in order to guarantee a correct parse tree in all cases.
Created attachment 114103 [details] [review] proposed fix I realized I should simplify the code the moment I sent the first patch, sorry.
Please use spaces for indentation, instead of tabs. Have a look at the HACKING file for more information.
Created attachment 114493 [details] [review] proposed fix reformatted patch
Thanks a lot Michael! I committed this to trunk.