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 = []