mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Back out change to raise exceptions if the lookup key doesn't exist. Breaks naked searching for items containing colons.
This commit is contained in:
parent
3e05f78637
commit
b771277985
@ -592,7 +592,8 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
candidates = self.universal_set()
|
candidates = self.universal_set()
|
||||||
if len(candidates) == 0:
|
if len(candidates) == 0:
|
||||||
return matches
|
return matches
|
||||||
self.test_location_is_valid(location, query)
|
if location not in self.all_search_locations:
|
||||||
|
return matches
|
||||||
|
|
||||||
if len(location) > 2 and location.startswith('@') and \
|
if len(location) > 2 and location.startswith('@') and \
|
||||||
location[1:] in self.db_prefs['grouped_search_terms']:
|
location[1:] in self.db_prefs['grouped_search_terms']:
|
||||||
|
@ -19,8 +19,8 @@ If this module is run, it will perform a series of unit tests.
|
|||||||
import sys, string, operator
|
import sys, string, operator
|
||||||
|
|
||||||
from calibre.utils.pyparsing import CaselessKeyword, Group, Forward, \
|
from calibre.utils.pyparsing import CaselessKeyword, Group, Forward, \
|
||||||
CharsNotIn, Suppress, OneOrMore, MatchFirst, alphas, alphanums, \
|
CharsNotIn, Suppress, OneOrMore, MatchFirst, CaselessLiteral, \
|
||||||
Optional, ParseException, QuotedString, Word
|
Optional, NoMatch, ParseException, QuotedString
|
||||||
from calibre.constants import preferred_encoding
|
from calibre.constants import preferred_encoding
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
|
|
||||||
@ -128,9 +128,12 @@ class SearchQueryParser(object):
|
|||||||
self._tests_failed = False
|
self._tests_failed = False
|
||||||
self.optimize = optimize
|
self.optimize = optimize
|
||||||
# Define a token
|
# Define a token
|
||||||
self.standard_locations = locations
|
standard_locations = map(lambda x : CaselessLiteral(x)+Suppress(':'),
|
||||||
location = Optional(Word(alphas+'#', bodyChars=alphanums+'_')+Suppress(':'),
|
locations)
|
||||||
default='all')
|
location = NoMatch()
|
||||||
|
for l in standard_locations:
|
||||||
|
location |= l
|
||||||
|
location = Optional(location, default='all')
|
||||||
word_query = CharsNotIn(string.whitespace + '()')
|
word_query = CharsNotIn(string.whitespace + '()')
|
||||||
#quoted_query = Suppress('"')+CharsNotIn('"')+Suppress('"')
|
#quoted_query = Suppress('"')+CharsNotIn('"')+Suppress('"')
|
||||||
quoted_query = QuotedString('"', escChar='\\')
|
quoted_query = QuotedString('"', escChar='\\')
|
||||||
@ -247,14 +250,7 @@ class SearchQueryParser(object):
|
|||||||
raise ParseException(query, len(query), 'undefined saved search', self)
|
raise ParseException(query, len(query), 'undefined saved search', self)
|
||||||
return self._get_matches(location, query, candidates)
|
return self._get_matches(location, query, candidates)
|
||||||
|
|
||||||
def test_location_is_valid(self, location, query):
|
|
||||||
if location not in self.standard_locations:
|
|
||||||
raise ParseException(query, len(query),
|
|
||||||
_('No column exists with lookup name ') + location, self)
|
|
||||||
|
|
||||||
def _get_matches(self, location, query, candidates):
|
def _get_matches(self, location, query, candidates):
|
||||||
location = location.lower()
|
|
||||||
self.test_location_is_valid(location, query)
|
|
||||||
if self.optimize:
|
if self.optimize:
|
||||||
return self.get_matches(location, query, candidates=candidates)
|
return self.get_matches(location, query, candidates=candidates)
|
||||||
else:
|
else:
|
||||||
@ -658,4 +654,3 @@ if __name__ == '__main__':
|
|||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user