Updated advanced search query
authorThierry Florac <tflorac@ulthar.net>
Mon, 20 Jul 2020 10:42:33 +0200
changeset 165 1945b374d388
parent 164 e48a3850c17a
child 166 0c536f62e02a
Updated advanced search query
src/pyams_content_es/root/zmi/search.py
src/pyams_content_es/shared/zmi/search.py
--- a/src/pyams_content_es/root/zmi/search.py	Sun Jul 19 02:11:57 2020 +0200
+++ b/src/pyams_content_es/root/zmi/search.py	Mon Jul 20 10:42:33 2020 +0200
@@ -101,19 +101,13 @@
             else:
                 fulltext = data.get('fulltext', False)
                 if fulltext:
-                    params &= Q('simple_query_string', query=query)
+                    params &= Q('simple_query_string',
+                                query=query)
                 else:
-                    negotiator = get_utility(INegotiator)
-                    query_params = Q('bool')
-                    for lang in {self.request.registry.settings.get('pyramid.default_locale_name',
-                                                                    'en'),
-                                 self.request.locale_name,
-                                 negotiator.server_language} | negotiator.offered_languages:
-                        query_params |= Q('match', **{'title.{}'.format(lang): query})
-                        query_params |= Q('match', **{'short_name.{}'.format(lang): query})
-                        query_params |= Q('match', **{'header.{}'.format(lang): query})
-                        query_params |= Q('match', **{'description.{}'.format(lang): query})
-                    params &= query_params
+                    params &= Q('simple_query_string',
+                                query=query,
+                                fields=['title.*', 'short_name.*', 'header.*', 'description.*'],
+                                default_operator='and')
         if data.get('owner'):
             params &= Q('term', owner_id=data['owner'])
         if data.get('created_after'):
--- a/src/pyams_content_es/shared/zmi/search.py	Sun Jul 19 02:11:57 2020 +0200
+++ b/src/pyams_content_es/shared/zmi/search.py	Mon Jul 20 10:42:33 2020 +0200
@@ -27,7 +27,6 @@
     SharedToolAdvancedSearchForm, SharedToolAdvancedSearchResultsView, \
     SharedToolAdvancedSearchView
 from pyams_form.interfaces.form import ISearchFormFactory
-from pyams_i18n.interfaces import INegotiator
 from pyams_sequence.interfaces import ISequentialIntIds
 from pyams_sequence.reference import get_last_version
 from pyams_skin.interfaces import IContentSearch
@@ -101,19 +100,13 @@
             else:
                 fulltext = data.get('fulltext', False)
                 if fulltext:
-                    params &= Q('simple_query_string', query=query)
+                    params &= Q('simple_query_string',
+                                query=query)
                 else:
-                    negotiator = get_utility(INegotiator)
-                    query_params = Q('bool')
-                    for lang in {self.request.registry.settings.get('pyramid.default_locale_name',
-                                                                    'en'),
-                                 self.request.locale_name,
-                                 negotiator.server_language} | negotiator.offered_languages:
-                        query_params |= Q('match', **{'title.{}'.format(lang): query})
-                        query_params |= Q('match', **{'short_name.{}'.format(lang): query})
-                        query_params |= Q('match', **{'header.{}'.format(lang): query})
-                        query_params |= Q('match', **{'description.{}'.format(lang): query})
-                    params &= query_params
+                    params &= Q('simple_query_string',
+                                query=query,
+                                fields=['title.*', 'short_name.*', 'header.*', 'description.*'],
+                                default_operator='and')
         if data.get('owner'):
             params &= Q('term', owner_id=data['owner'])
         if data.get('status'):