include broader terms when searching a thesaurus term (#4570)
This commit is contained in:
parent
ca14ea0a5c
commit
8de1915000
|
@ -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()
|
||||
|
|
|
@ -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')
|
||||
|
|
Reference in New Issue