Search by rating:#. Also include rating in default search.

This commit is contained in:
John Schember 2009-06-29 21:28:23 -04:00
parent 7e493d1b01
commit 6b8905d272
2 changed files with 12 additions and 2 deletions

View File

@ -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):

View File

@ -50,6 +50,7 @@ class SearchQueryParser(object):
'author', 'author',
'publisher', 'publisher',
'series', 'series',
'rating',
'comments', 'comments',
'format', 'format',
'isbn', 'isbn',