From 5010f768d422360d3fb0b2ab8ed994a8ea3df588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sat, 22 Dec 2012 09:39:09 +0100 Subject: [PATCH] Use regexp during search computation --- search.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/search.py b/search.py index 890ed94..34ce1d7 100644 --- a/search.py +++ b/search.py @@ -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]: - if not post[0] in res: - res[post[0]] = post[1] - res[post[0]] += post[1] - sorted_res = sorted(res.iteritems(), key=operator.itemgetter(1)) + 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.reverse() res = []