From 8de19150000458aa253490eaff30876b687e8c3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 26 Mar 2014 11:49:23 +0100 Subject: [PATCH] include broader terms when searching a thesaurus term (#4570) --- .../dms/thesaurus/browser/thesaurusview.py | 20 +++++++++++++++---- src/collective/dms/thesaurus/indexers.py | 7 +------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/collective/dms/thesaurus/browser/thesaurusview.py b/src/collective/dms/thesaurus/browser/thesaurusview.py index 4bfc144..9f8412d 100644 --- a/src/collective/dms/thesaurus/browser/thesaurusview.py +++ b/src/collective/dms/thesaurus/browser/thesaurusview.py @@ -86,18 +86,22 @@ class ListKeywordsView(BrowserView): _items = None - def getItems(self): + def getItems(self, query=None): context = self.context if self._items is not None: return self._items titles = list() self._items = list() + kwargs = {} + if query: + kwargs['SearchableText'] = query + catalog = getToolByName(context, 'portal_catalog') path = '/'.join(context.getPhysicalPath()) for brain in catalog(portal_type='dmskeyword', - path={'query': path,'depth': 1} - ) : + path={'query': path,'depth': 1}, + **kwargs): obj = brain.getObject() normalized = normalizer.normalize(obj.title).lower() if normalized in titles: @@ -129,12 +133,14 @@ class ListKeywordsView(BrowserView): other = [] q = query_string.lower() regex = re.compile(r"[\s'()]") - items = self.getItems() + items = self.getItems(query_string) + done = {} for normalized, title, id in items: 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)) @@ -146,6 +152,12 @@ class ListKeywordsView(BrowserView): else: other.append((normalized, item)) + for normalized, title, id in items: + if done.get(id): + continue + item = '%s|%s' % (title, id) + other.append((normalized, item)) + startswith.sort() intermediate.sort() other.sort() diff --git a/src/collective/dms/thesaurus/indexers.py b/src/collective/dms/thesaurus/indexers.py index 4ce14a4..56a8657 100644 --- a/src/collective/dms/thesaurus/indexers.py +++ b/src/collective/dms/thesaurus/indexers.py @@ -10,11 +10,6 @@ class IDmsKeywordIndexer(Interface): @indexer(IDmsKeywordIndexer) def dmskeyword_searchable_text(obj): - indexed_fields = [] - title = unicode(obj.Title(), 'utf-8') - indexed_fields.append(title) - if obj.equivs: - indexed_fields.extend([x for x in obj.equivs if x]) - return u' '.join(indexed_fields) + return obj.get_words_for_indexation() grok.global_adapter(dmskeyword_searchable_text, name='SearchableText')