Basic search works for now

This commit is contained in:
2012-12-10 19:30:25 +01:00
parent 0b61fa7ff2
commit 2f1f38ca5c
16 changed files with 185 additions and 29 deletions

View File

@@ -50,6 +50,7 @@ class Search:
filename = blog.src_path + '/_search.db'
if not os.path.exists(filename):
print 'No search index !'
return None
f = open(filename, 'rb')
@@ -169,16 +170,16 @@ class Search:
def search(self, blog, string):
hashtable = self._loadDatabase(blog)
string = self._prepare_string(string)
string = self._prepare_string(string.encode('utf-8'))
wordlist = re.findall(self.wordreg, string)
res = {}
for word in wordlist:
if len(word) < 4:
if len(word) < Search.MINIMUM_LETTERS:
continue
word = word.lower()
while not word in hashtable and len(word) > 3:
while not word in hashtable and len(word) > Search.MINIMUM_LETTERS:
word = word[:-1]
if word not in hashtable:
continue
@@ -186,7 +187,11 @@ class Search:
if not post in res:
res[post] = 0
res[post] = res[post] + 1
sorted_res = sorted(res.iteritems(), key=operator.itemgetter(1))
return sorted_res.reverse()
sorted_res.reverse()
res = []
for i in range(len(sorted_res)):
res .append(sorted_res[i][0])
return res