# HG changeset patch # User Thierry Florac # Date 1548412921 -3600 # Node ID c9f9e7036daf41cbca6ed7bd938d4c2b086e1dbf # Parent cae08a8096fa9d753acd50fff36a7a0f3e8033fb Switch search results sort on publication date if relevance is used without user query diff -r cae08a8096fa -r c9f9e7036daf src/pyams_content/features/search/portlet/__init__.py --- a/src/pyams_content/features/search/portlet/__init__.py Thu Jan 24 11:38:45 2019 +0100 +++ b/src/pyams_content/features/search/portlet/__init__.py Fri Jan 25 11:42:01 2019 +0100 @@ -20,7 +20,7 @@ from pyams_content import _ from pyams_content.features.search import ISearchFolder from pyams_content.features.search.portlet.interfaces import ISearchResultsPortletSettings -from pyams_content.shared.view.interfaces import RELEVANCE_ORDER +from pyams_content.shared.view.interfaces import RELEVANCE_ORDER, VISIBLE_PUBLICATION_DATE_ORDER from pyams_portal.portlet import Portlet, PortletSettings, portlet_config from pyams_utils.factory import factory_config from pyams_utils.interfaces import VIEW_PERMISSION @@ -53,9 +53,11 @@ if request is None: request = check_request() params = request.params - sort_index = params.get('order_by', context.order_by) - yield from context.get_results(context, sort_index, - reverse=sort_index != RELEVANCE_ORDER, + order_by = params.get('order_by', context.order_by) + if (order_by == RELEVANCE_ORDER) and not SearchResultsPortletSettings.has_user_query(request): + request.GET['order_by'] = order_by = VISIBLE_PUBLICATION_DATE_ORDER + yield from context.get_results(context, order_by, + reverse=order_by != RELEVANCE_ORDER, limit=limit, start=int(params.get('start', 0)), length=int(params.get('length', 10)),