summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2014-03-26 15:11:32 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2014-03-26 15:11:32 (GMT)
commitd20b6b4e5cd2ed8fbaa5466eb9f8014b400af388 (patch)
tree6f3a8210dcdc4ee6b0dde10298a96f8b9f2da254
parent8de19150000458aa253490eaff30876b687e8c3e (diff)
downloadcollective.dms.thesaurus-d20b6b4e5cd2ed8fbaa5466eb9f8014b400af388.zip
collective.dms.thesaurus-d20b6b4e5cd2ed8fbaa5466eb9f8014b400af388.tar.gz
collective.dms.thesaurus-d20b6b4e5cd2ed8fbaa5466eb9f8014b400af388.tar.bz2
rewrite live search results to still be pertinent (#4570)
-rw-r--r--src/collective/dms/thesaurus/browser/thesaurusview.py40
1 files changed, 20 insertions, 20 deletions
diff --git a/src/collective/dms/thesaurus/browser/thesaurusview.py b/src/collective/dms/thesaurus/browser/thesaurusview.py
index 9f8412d..1ddd386 100644
--- a/src/collective/dms/thesaurus/browser/thesaurusview.py
+++ b/src/collective/dms/thesaurus/browser/thesaurusview.py
@@ -128,42 +128,42 @@ class ListKeywordsView(BrowserView):
query_string = unicode(self.request.form.get('q'), 'utf-8')
query_terms = [normalizer.normalize(x) for x in query_string.split()]
+ absolute_startswith = []
startswith = []
intermediate = []
other = []
q = query_string.lower()
regex = re.compile(r"[\s'()]")
+ q_words = regex.split(q)
items = self.getItems(query_string)
done = {}
for normalized, title, id in items:
+ count_start = 0
+ count_in = 0
for term in query_terms:
- if not term in normalized.lower():
- break
- else:
- done[id] = True
- item = '%s|%s' % (title, id)
- 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 word in regex.split(normalized):
+ if word.lower().startswith(term):
+ count_start += 1
+ elif term in word.lower():
+ count_in += 1
- for normalized, title, id in items:
- if done.get(id):
- continue
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()
intermediate.sort()
other.sort()
result = list()
- for _list in (startswith, intermediate, other):
+ for _list in (absolute_startswith, startswith, intermediate, other):
for item in _list:
result.append(item[1])
if len(result) > 29: