User category searching

This commit is contained in:
Kovid Goyal 2013-01-21 11:43:57 +05:30
parent f4fb43875f
commit 5000f5c133
3 changed files with 28 additions and 0 deletions

View File

@ -525,8 +525,35 @@ class Parser(SearchQueryParser):
candidates, upf)
return self.keypair_search(query, field_iter, candidates, upf)
# check for user categories
if len(location) >= 2 and location.startswith('@'):
return self.get_user_category_matches(location[1:], icu_lower(query), candidates)
return matches
def get_user_category_matches(self, location, query, candidates):
matches = set()
if len(query) < 2:
return matches
user_cats = self.dbcache.pref('user_categories')
c = set(candidates)
if query.startswith('.'):
check_subcats = True
query = query[1:]
else:
check_subcats = False
for key in user_cats:
if key == location or (check_subcats and key.startswith(location + '.')):
for (item, category, ign) in user_cats[key]:
s = self.get_matches(category, '=' + item, candidates=c)
c -= s
matches |= s
if query == 'false':
return candidates - matches
return matches
class Search(object):

Binary file not shown.

View File

@ -220,6 +220,7 @@ class ReadingTest(BaseTest):
# TODO: Tests for searching the size column and
# cover:true|false
# TODO: Tests for user categories searching
)}
old = None