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
1 changed files with 9 additions and 9 deletions

View File

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