summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2014-03-26 10:49:23 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2014-03-26 10:49:23 (GMT)
commit8de19150000458aa253490eaff30876b687e8c3e (patch)
treeaa9bce3e734e33f7a519562f515c63d2625fda52
parentca14ea0a5cea9edc80896080dd2075771cea0954 (diff)
downloadcollective.dms.thesaurus-8de19150000458aa253490eaff30876b687e8c3e.zip
collective.dms.thesaurus-8de19150000458aa253490eaff30876b687e8c3e.tar.gz
collective.dms.thesaurus-8de19150000458aa253490eaff30876b687e8c3e.tar.bz2
include broader terms when searching a thesaurus term (#4570)
-rw-r--r--src/collective/dms/thesaurus/browser/thesaurusview.py20
-rw-r--r--src/collective/dms/thesaurus/indexers.py7
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')