From 3a3dac08c66e5badb593687cb683a7102f77e394 Mon Sep 17 00:00:00 2001 From: Razvan Date: Thu, 29 Feb 2024 18:14:56 +0200 Subject: [PATCH 1/2] feat(catalog): add rids parameter to return only the rids of documents --- src/Products/ZCatalog/Catalog.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Products/ZCatalog/Catalog.py b/src/Products/ZCatalog/Catalog.py index 95c893d5..c92f7856 100644 --- a/src/Products/ZCatalog/Catalog.py +++ b/src/Products/ZCatalog/Catalog.py @@ -588,7 +588,7 @@ def _search_index(self, cr, index_id, query, rs): return rs def search(self, query, - sort_index=None, reverse=False, limit=None, merge=True): + sort_index=None, reverse=False, limit=None, merge=True, rids=False): """Iterate through the indexes, applying the query to each one. If merge is true then return a lazy result set (sorted if appropriate) otherwise return the raw (possibly scored) results for later merging. @@ -634,6 +634,10 @@ def search(self, query, cr.stop() return result + if rids: + cr.stop() + return rs + # Try to deduce the sort limit from batching arguments. b_start, b_size, limit, sort_report_name = self._sort_limit_arguments( query, sort_index, reverse, limit) @@ -1061,7 +1065,7 @@ def _getSortIndex(self, args): return sort_indexes return None - def searchResults(self, query=None, _merge=True, **kw): + def searchResults(self, query=None, _merge=True, rids=False, **kw): # You should pass in a simple dictionary as the first argument, # which only contains the relevant query. query = self.merge_query_args(query, **kw) @@ -1081,7 +1085,7 @@ def searchResults(self, query=None, _merge=True, **kw): # be nice and keep the old API intact for single sort_order reverse = reverse[0] # Perform searches with indexes and sort_index - return self.search(query, sort_indexes, reverse, sort_limit, _merge) + return self.search(query, sort_indexes, reverse, sort_limit, _merge, rids) __call__ = searchResults From 1e0571601892b8b3e1c053da2d91097a6803bd0c Mon Sep 17 00:00:00 2001 From: Miu Razvan Date: Tue, 26 Mar 2024 16:39:26 +0200 Subject: [PATCH 2/2] lint fix --- src/Products/ZCatalog/Catalog.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Products/ZCatalog/Catalog.py b/src/Products/ZCatalog/Catalog.py index c92f7856..6db61c3e 100644 --- a/src/Products/ZCatalog/Catalog.py +++ b/src/Products/ZCatalog/Catalog.py @@ -587,8 +587,9 @@ def _search_index(self, cr, index_id, query, rs): return rs - def search(self, query, - sort_index=None, reverse=False, limit=None, merge=True, rids=False): + def search( + self, query, sort_index=None, reverse=False, limit=None, + merge=True, rids=False): """Iterate through the indexes, applying the query to each one. If merge is true then return a lazy result set (sorted if appropriate) otherwise return the raw (possibly scored) results for later merging. @@ -1085,7 +1086,8 @@ def searchResults(self, query=None, _merge=True, rids=False, **kw): # be nice and keep the old API intact for single sort_order reverse = reverse[0] # Perform searches with indexes and sort_index - return self.search(query, sort_indexes, reverse, sort_limit, _merge, rids) + return self.search( + query, sort_indexes, reverse, sort_limit, _merge, rids) __call__ = searchResults