--- a/src/pyams_content/features/search/portlet/__init__.py Wed Dec 12 16:03:05 2018 +0100
+++ b/src/pyams_content/features/search/portlet/__init__.py Wed Dec 12 17:22:59 2018 +0100
@@ -13,6 +13,7 @@
__docformat__ = 'restructuredtext'
import math
+from itertools import tee
from zope.schema.fieldproperty import FieldProperty
@@ -38,21 +39,32 @@
title = FieldProperty(ISearchResultsPortletSettings['title'])
@staticmethod
- def get_items(request=None, limit=None, ignore_cache=False):
+ def _get_items(request=None, limit=None, ignore_cache=False):
context = get_parent(request.context, ISearchFolder)
if context is None:
raise StopIteration
- if request is None:
- request = check_request()
- params = request.params
- sort_index = params.get('order_by', RELEVANCE_ORDER)
- yield from context.get_results(context, sort_index,
- reverse=sort_index != RELEVANCE_ORDER,
- limit=limit,
- start=int(params.get('start', 0)),
- length=int(params.get('length', 10)),
- ignore_cache=ignore_cache,
- get_count=True)
+ else:
+ if request is None:
+ request = check_request()
+ params = request.params
+ sort_index = params.get('order_by', RELEVANCE_ORDER)
+ yield from context.get_results(context, sort_index,
+ reverse=sort_index != RELEVANCE_ORDER,
+ limit=limit,
+ start=int(params.get('start', 0)),
+ length=int(params.get('length', 10)),
+ ignore_cache=ignore_cache,
+ get_count=True)
+
+ @staticmethod
+ def get_items(request=None, limit=None, ignore_cache=False):
+ check, items = tee(SearchResultsPortletSettings._get_items(request, limit, ignore_cache))
+ try:
+ next(check)
+ except StopIteration:
+ yield from iter(((), 0),)
+ else:
+ yield from items
@staticmethod
def get_pages(request, count):