mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-07 09:01:38 -04:00
Search by rating:#. Also include rating in default search.
This commit is contained in:
parent
7e493d1b01
commit
6b8905d272
@ -198,22 +198,31 @@ class ResultCache(SearchQueryParser):
|
|||||||
query = query.decode('utf-8')
|
query = query.decode('utf-8')
|
||||||
if location in ('tag', 'author', 'format'):
|
if location in ('tag', 'author', 'format'):
|
||||||
location += 's'
|
location += 's'
|
||||||
all = ('title', 'authors', 'publisher', 'tags', 'comments', 'series', 'formats', 'isbn')
|
all = ('title', 'authors', 'publisher', 'tags', 'comments', 'series', 'formats', 'isbn', 'rating')
|
||||||
MAP = {}
|
MAP = {}
|
||||||
for x in all:
|
for x in all:
|
||||||
MAP[x] = FIELD_MAP[x]
|
MAP[x] = FIELD_MAP[x]
|
||||||
|
EXCLUDE_FIELDS = [MAP['rating']]
|
||||||
location = [location] if location != 'all' else list(MAP.keys())
|
location = [location] if location != 'all' else list(MAP.keys())
|
||||||
for i, loc in enumerate(location):
|
for i, loc in enumerate(location):
|
||||||
location[i] = MAP[loc]
|
location[i] = MAP[loc]
|
||||||
|
try:
|
||||||
|
rating_query = int(query) * 2
|
||||||
|
except:
|
||||||
|
rating_query = None
|
||||||
for item in self._data:
|
for item in self._data:
|
||||||
if item is None: continue
|
if item is None: continue
|
||||||
for loc in location:
|
for loc in location:
|
||||||
if (not item[loc] or item[loc] == [] or item[loc] == 0 or item[loc] == '') and query == 'none':
|
if (not item[loc] or item[loc] == [] or item[loc] == 0 or item[loc] == '') and query == 'none':
|
||||||
matches.add(item[0])
|
matches.add(item[0])
|
||||||
break
|
break
|
||||||
if item[loc] and query in item[loc].lower():
|
if rating_query and item[loc] and loc == MAP['rating'] and rating_query == int(item[loc]):
|
||||||
matches.add(item[0])
|
matches.add(item[0])
|
||||||
break
|
break
|
||||||
|
if item[loc] and loc not in EXCLUDE_FIELDS and query in item[loc].lower():
|
||||||
|
matches.add(item[0])
|
||||||
|
break
|
||||||
|
|
||||||
return matches
|
return matches
|
||||||
|
|
||||||
def remove(self, id):
|
def remove(self, id):
|
||||||
|
@ -50,6 +50,7 @@ class SearchQueryParser(object):
|
|||||||
'author',
|
'author',
|
||||||
'publisher',
|
'publisher',
|
||||||
'series',
|
'series',
|
||||||
|
'rating',
|
||||||
'comments',
|
'comments',
|
||||||
'format',
|
'format',
|
||||||
'isbn',
|
'isbn',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user