Updated dashboard quick search engine
authorThierry Florac <thierry.florac@onf.fr>
Mon, 10 Dec 2018 13:49:22 +0100
changeset 1150 ce2a61685c8c
parent 1149 d362f48f9a2c
child 1151 789e9f5c510e
Updated dashboard quick search engine
src/pyams_content/root/zmi/search.py
src/pyams_content/shared/common/zmi/search.py
--- a/src/pyams_content/root/zmi/search.py	Fri Dec 07 16:13:17 2018 +0100
+++ b/src/pyams_content/root/zmi/search.py	Mon Dec 10 13:49:22 2018 +0100
@@ -110,15 +110,15 @@
     def values(self):
         intids = get_utility(IIntIds)
         catalog = get_utility(ICatalog)
-        params = Eq(catalog['parents'], intids.register(self.context)) & \
-            Any(catalog['content_type'], CONTENT_TYPES.keys())
         query = self.request.params.get('query')
         if query:
             sequence = get_utility(ISequentialIntIds)
             query = query.lower()
             if query.startswith('+'):
-                params &= Eq(catalog['oid'], sequence.get_full_oid(query))
+                params = Eq(catalog['oid'], sequence.get_full_oid(query))
             else:
+                params = Eq(catalog['parents'], intids.register(self.context)) & \
+                         Any(catalog['content_type'], CONTENT_TYPES.keys())
                 query_params = Eq(catalog['oid'], sequence.get_full_oid(query))
                 negotiator = get_utility(INegotiator)
                 for lang in {self.request.registry.settings.get('pyramid.default_locale_name', 'en'),
@@ -130,10 +130,12 @@
                         if index.check_query(query):
                             query_params |= Contains(index, ' and '.join((w+'*' for w in query.split())))
                 params &= query_params
-        return unique(map(get_last_version,
-                          CatalogResultSet(CatalogQuery(catalog).query(params,
-                                                                       sort_index='modified_date',
-                                                                       reverse=True))))
+            return unique(map(get_last_version,
+                              CatalogResultSet(CatalogQuery(catalog).query(params,
+                                                                           sort_index='modified_date',
+                                                                           reverse=True))))
+        else:
+            return ()
 
 
 #
--- a/src/pyams_content/shared/common/zmi/search.py	Fri Dec 07 16:13:17 2018 +0100
+++ b/src/pyams_content/shared/common/zmi/search.py	Mon Dec 10 13:49:22 2018 +0100
@@ -112,15 +112,15 @@
     def values(self):
         intids = get_utility(IIntIds)
         catalog = get_utility(ICatalog)
-        params = Eq(catalog['parents'], intids.register(self.context)) & \
-            Any(catalog['content_type'], CONTENT_TYPES.keys())
         query = self.request.params.get('query')
         if query:
             sequence = get_utility(ISequentialIntIds)
             query = query.lower()
             if query.startswith('+'):
-                params &= Eq(catalog['oid'], sequence.get_full_oid(query))
+                params = Eq(catalog['oid'], sequence.get_full_oid(query))
             else:
+                params = Eq(catalog['parents'], intids.register(self.context)) & \
+                         Any(catalog['content_type'], CONTENT_TYPES.keys())
                 query_params = Eq(catalog['oid'], sequence.get_full_oid(query))
                 negotiator = get_utility(INegotiator)
                 for lang in {self.request.registry.settings.get('pyramid.default_locale_name', 'en'),
@@ -132,10 +132,12 @@
                         if index.check_query(query):
                             query_params |= Contains(index, ' and '.join((w+'*' for w in query.split())))
                 params &= query_params
-        return unique(map(get_last_version,
-                          CatalogResultSet(CatalogQuery(catalog).query(params,
-                                                                       sort_index='modified_date',
-                                                                       reverse=True))))
+            return unique(map(get_last_version,
+                              CatalogResultSet(CatalogQuery(catalog).query(params,
+                                                                           sort_index='modified_date',
+                                                                           reverse=True))))
+        else:
+            return ()
 
 
 #