libsaria: Filter library

This reduces the number of visible songs that the user sees on the UI.
This commit is contained in:
Bryan Schumaker 2011-05-21 22:28:12 -04:00
parent ad12bf6500
commit 248dd283ff
1 changed files with 25 additions and 1 deletions

View File

@ -1,11 +1,13 @@
# Bryan Schumaker (5 / 21 / 2011)
import re
import string
import library
lib_index = dict()
all_ids = set()
matching = set()
search = re.search
space_ord = ord(" ")
stripc = u"\"#$%&'*+<=>@[]^`{|}~.?!"
@ -45,5 +47,27 @@ def reindex():
def is_visible(id):
return id in matching
def do_filter(terms):
if len(terms) == 0:
return all_ids
get = lib_index.get
results = dict((t, set()) for t in terms)
for key in lib_index.keys():
for term in terms:
if search(term, key):
results[term].update(get(key))
visible = set()
for i, t in enumerate(terms):
if i == 0:
visible.update(results[t])
else:
visible.intersection_update(results[t])
return visible
def filter(text):
print text
global matching
text = unicode(text)
terms = format(text)
matching = do_filter(terms)