mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Make SearchQueryParser accept a dynamic list of locations
This commit is contained in:
parent
b060a20f71
commit
bb7edaa57b
@ -155,7 +155,9 @@ class ResultCache(SearchQueryParser):
|
|||||||
self._map = self._map_filtered = self._data = []
|
self._map = self._map_filtered = self._data = []
|
||||||
self.first_sort = True
|
self.first_sort = True
|
||||||
self.search_restriction = ''
|
self.search_restriction = ''
|
||||||
SearchQueryParser.__init__(self, [c for c in cc_label_map])
|
SearchQueryParser.__init__(self,
|
||||||
|
locations=SearchQueryParser.DEFAULT_LOCATIONS +
|
||||||
|
[c for c in cc_label_map])
|
||||||
self.build_relop_dict()
|
self.build_relop_dict()
|
||||||
|
|
||||||
def build_relop_dict(self):
|
def build_relop_dict(self):
|
||||||
|
@ -73,7 +73,7 @@ class SearchQueryParser(object):
|
|||||||
When no operator is specified between two tokens, `and` is assumed.
|
When no operator is specified between two tokens, `and` is assumed.
|
||||||
|
|
||||||
Each token is a string of the form `location:query`. `location` is a string
|
Each token is a string of the form `location:query`. `location` is a string
|
||||||
from :member:`LOCATIONS`. It is optional. If it is omitted, it is assumed to
|
from :member:`DEFAULT_LOCATIONS`. It is optional. If it is omitted, it is assumed to
|
||||||
be `all`. `query` is an arbitrary string that must not contain parentheses.
|
be `all`. `query` is an arbitrary string that must not contain parentheses.
|
||||||
If it contains whitespace, it should be quoted by enclosing it in `"` marks.
|
If it contains whitespace, it should be quoted by enclosing it in `"` marks.
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ class SearchQueryParser(object):
|
|||||||
* `(author:Asimov or author:Hardy) and not tag:read` [search for unread books by Asimov or Hardy]
|
* `(author:Asimov or author:Hardy) and not tag:read` [search for unread books by Asimov or Hardy]
|
||||||
'''
|
'''
|
||||||
|
|
||||||
LOCATIONS = [
|
DEFAULT_LOCATIONS = [
|
||||||
'tag',
|
'tag',
|
||||||
'title',
|
'title',
|
||||||
'author',
|
'author',
|
||||||
@ -116,10 +116,13 @@ class SearchQueryParser(object):
|
|||||||
failed.append(test[0])
|
failed.append(test[0])
|
||||||
return failed
|
return failed
|
||||||
|
|
||||||
def __init__(self, custcols=[], test=False):
|
def __init__(self, locations=None, test=False):
|
||||||
|
if locations is None:
|
||||||
|
locations = self.DEFAULT_LOCATIONS
|
||||||
self._tests_failed = False
|
self._tests_failed = False
|
||||||
# Define a token
|
# Define a token
|
||||||
standard_locations = map(lambda x : CaselessLiteral(x)+Suppress(':'), self.LOCATIONS+custcols)
|
standard_locations = map(lambda x : CaselessLiteral(x)+Suppress(':'),
|
||||||
|
locations)
|
||||||
location = NoMatch()
|
location = NoMatch()
|
||||||
for l in standard_locations:
|
for l in standard_locations:
|
||||||
location |= l
|
location |= l
|
||||||
@ -228,7 +231,7 @@ class SearchQueryParser(object):
|
|||||||
'''
|
'''
|
||||||
Should return the set of matches for :param:'location` and :param:`query`.
|
Should return the set of matches for :param:'location` and :param:`query`.
|
||||||
|
|
||||||
:param:`location` is one of the items in :member:`SearchQueryParser.LOCATIONS`.
|
:param:`location` is one of the items in :member:`SearchQueryParser.DEFAULT_LOCATIONS`.
|
||||||
:param:`query` is a string literal.
|
:param:`query` is a string literal.
|
||||||
'''
|
'''
|
||||||
return set([])
|
return set([])
|
||||||
|
@ -121,7 +121,7 @@ class RecipeModel(QAbstractItemModel, SearchQueryParser):
|
|||||||
|
|
||||||
def __init__(self, db, *args):
|
def __init__(self, db, *args):
|
||||||
QAbstractItemModel.__init__(self, *args)
|
QAbstractItemModel.__init__(self, *args)
|
||||||
SearchQueryParser.__init__(self)
|
SearchQueryParser.__init__(self, locations=['all'])
|
||||||
self.db = db
|
self.db = db
|
||||||
self.default_icon = QVariant(QIcon(I('news.svg')))
|
self.default_icon = QVariant(QIcon(I('news.svg')))
|
||||||
self.custom_icon = QVariant(QIcon(I('user_profile.svg')))
|
self.custom_icon = QVariant(QIcon(I('user_profile.svg')))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user