rewrite live search results to still be pertinent (#4570)
This commit is contained in:
parent
8de1915000
commit
d20b6b4e5c
|
@ -128,42 +128,42 @@ class ListKeywordsView(BrowserView):
|
||||||
query_string = unicode(self.request.form.get('q'), 'utf-8')
|
query_string = unicode(self.request.form.get('q'), 'utf-8')
|
||||||
query_terms = [normalizer.normalize(x) for x in query_string.split()]
|
query_terms = [normalizer.normalize(x) for x in query_string.split()]
|
||||||
|
|
||||||
|
absolute_startswith = []
|
||||||
startswith = []
|
startswith = []
|
||||||
intermediate = []
|
intermediate = []
|
||||||
other = []
|
other = []
|
||||||
q = query_string.lower()
|
q = query_string.lower()
|
||||||
regex = re.compile(r"[\s'()]")
|
regex = re.compile(r"[\s'()]")
|
||||||
|
q_words = regex.split(q)
|
||||||
items = self.getItems(query_string)
|
items = self.getItems(query_string)
|
||||||
done = {}
|
done = {}
|
||||||
for normalized, title, id in items:
|
for normalized, title, id in items:
|
||||||
|
count_start = 0
|
||||||
|
count_in = 0
|
||||||
for term in query_terms:
|
for term in query_terms:
|
||||||
if not term in normalized.lower():
|
for word in regex.split(normalized):
|
||||||
break
|
if word.lower().startswith(term):
|
||||||
else:
|
count_start += 1
|
||||||
done[id] = True
|
elif term in word.lower():
|
||||||
item = '%s|%s' % (title, id)
|
count_in += 1
|
||||||
if normalized.lower().startswith(q):
|
|
||||||
startswith.append((normalized, item))
|
|
||||||
continue
|
|
||||||
for word in regex.split(normalized):
|
|
||||||
if word.lower().startswith(q):
|
|
||||||
intermediate.append((normalized, item))
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
other.append((normalized, item))
|
|
||||||
|
|
||||||
for normalized, title, id in items:
|
|
||||||
if done.get(id):
|
|
||||||
continue
|
|
||||||
item = '%s|%s' % (title, id)
|
item = '%s|%s' % (title, id)
|
||||||
other.append((normalized, item))
|
if count_start == len(query_terms):
|
||||||
|
absolute_startswith.append((normalized, item))
|
||||||
|
elif count_start >= 1:
|
||||||
|
startswith.append((normalized, item))
|
||||||
|
elif count_in:
|
||||||
|
intermediate.append((normalized, item))
|
||||||
|
else:
|
||||||
|
other.append((normalized, item))
|
||||||
|
|
||||||
|
absolute_startswith.sort()
|
||||||
startswith.sort()
|
startswith.sort()
|
||||||
intermediate.sort()
|
intermediate.sort()
|
||||||
other.sort()
|
other.sort()
|
||||||
|
|
||||||
result = list()
|
result = list()
|
||||||
for _list in (startswith, intermediate, other):
|
for _list in (absolute_startswith, startswith, intermediate, other):
|
||||||
for item in _list:
|
for item in _list:
|
||||||
result.append(item[1])
|
result.append(item[1])
|
||||||
if len(result) > 29:
|
if len(result) > 29:
|
||||||
|
|
Reference in New Issue