summaryrefslogtreecommitdiffstats
path: root/src/collective/dms/thesaurus/browser/thesaurusview.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/collective/dms/thesaurus/browser/thesaurusview.py')
-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: