Basic search works for now
This commit is contained in:
15
search.py
15
search.py
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user