Use regexp during search computation

This commit is contained in:
Grégory Soutadé 2012-12-22 09:39:09 +01:00
parent 12b43ffbed
commit 5010f768d4

View File

@ -192,16 +192,16 @@ class Search:
if len(word) < Search.MINIMUM_LETTERS:
continue
word = word.lower()
while not word in hashtable and len(word) > Search.MINIMUM_LETTERS:
word = word[:-1]
if word not in hashtable:
continue
for post in hashtable[word]:
reg = re.compile('.*' + word + '.*')
for key in hashtable.keys():
if reg.match(key):
for post in hashtable[key]:
if not post[0] in res:
res[post[0]] = post[1]
else:
res[post[0]] += post[1]
sorted_res = sorted(res.iteritems(), key=operator.itemgetter(1))
sorted_res = sorted(res.iteritems(), key=operator.itemgetter(1))
sorted_res.reverse()
res = []