From c6a6fe07cf2fb3f1002989d30ba23c635b30c921 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sun, 29 Apr 2018 11:00:37 +0200 Subject: [PATCH 1/2] Search parsing: fix using a parenthesized expression following an implied "and". --- src/calibre/utils/search_query_parser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calibre/utils/search_query_parser.py b/src/calibre/utils/search_query_parser.py index 466a800656..dbcfc7f13b 100644 --- a/src/calibre/utils/search_query_parser.py +++ b/src/calibre/utils/search_query_parser.py @@ -221,8 +221,8 @@ class Parser(object): return ['and', lhs, self.and_expression()] # Account for the optional 'and' - if (self.token_type() in [self.WORD, self.QUOTED_WORD] and - self.lcase_token() != 'or'): + if ((self.token_type() in [self.WORD, self.QUOTED_WORD] or self.token() == '(') + and self.lcase_token() != 'or'): return ['and', lhs, self.and_expression()] return lhs From bca1e6a0c5e6d5673fa53ed0d8bba1da4be66475 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sun, 29 Apr 2018 11:38:31 +0200 Subject: [PATCH 2/2] Add search query test to check a parenthesized expression after an implied "AND" --- src/calibre/utils/search_query_parser_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/calibre/utils/search_query_parser_test.py b/src/calibre/utils/search_query_parser_test.py index 15a29d42f6..6f7ba1ca45 100644 --- a/src/calibre/utils/search_query_parser_test.py +++ b/src/calibre/utils/search_query_parser_test.py @@ -322,6 +322,7 @@ class Tester(SearchQueryParser): 'author:S\\"calzi': {343}, '"S\\"calzi"': {343}, 'M\\\\cMurtry': {427}, + 'author:Tolstoy (tag:txt OR tag:pdf)': set([55, 56]), } fields = {'title':0, 'author':1, 'publisher':2, 'tag':3}