Allow direct search by OID (prefixed by +) in front-office
authorThierry Florac <tflorac@ulthar.net>
Fri, 14 Dec 2018 18:30:18 +0100
changeset 117 4ec0f32ec869
parent 116 23855cc6ae6d
child 118 17bc8afd7e4a
Allow direct search by OID (prefixed by +) in front-office
src/pyams_content_es/shared/view/__init__.py
--- a/src/pyams_content_es/shared/view/__init__.py	Fri Dec 14 13:33:30 2018 +0100
+++ b/src/pyams_content_es/shared/view/__init__.py	Fri Dec 14 18:30:18 2018 +0100
@@ -23,8 +23,10 @@
 from pyams_content.shared.view.interfaces import IViewQuery, IViewQueryEsParamsExtension, IViewQueryFilterExtension, \
     IViewUserQuery, IWfView, RELEVANCE_ORDER
 from pyams_content.shared.view.portlet import SEARCH_EXCLUDED_ITEMS
+from pyams_sequence.interfaces import ISequentialIntIds
 from pyams_utils.adapter import ContextAdapter, adapter_config
 from pyams_utils.list import unique_iter
+from pyams_utils.registry import get_utility
 from pyams_utils.timezone import tztime
 from pyams_workflow.interfaces import IWorkflow
 
@@ -148,4 +150,9 @@
         params = request.params
         fulltext = params.get('user_search')
         if fulltext:
-            yield Q('simple_query_string', **{'query': fulltext})
+            if fulltext.startswith('+'):
+                sequence = get_utility(ISequentialIntIds)
+                oid = sequence.get_full_oid(fulltext)
+                yield Q('term', **{'reference_id': oid})
+            else:
+                yield Q('simple_query_string', **{'query': fulltext})