Disable sorting when user entered a custom search string
authorThierry Florac <tflorac@ulthar.net>
Mon, 20 Jul 2020 12:33:08 +0200
changeset 166 0c536f62e02a
parent 165 1945b374d388
child 167 3fb0f88ee052
Disable sorting when user entered a custom search string
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	Mon Jul 20 10:42:33 2020 +0200
+++ b/src/pyams_content_es/root/zmi/search.py	Mon Jul 20 12:33:08 2020 +0200
@@ -70,6 +70,10 @@
         fields['fulltext'].widgetFactory = SingleCheckBoxFieldWidget
         return fields
 
+    @property
+    def sort_results(self):
+        return not bool(self.request.params.get('search_form.widgets.query'))
+
 
 @adapter_config(context=(ISiteRoot, IPyAMSLayer, SiteRootAdvancedSearchView),
                 provides=ISearchFormFactory)
--- a/src/pyams_content_es/shared/zmi/search.py	Mon Jul 20 10:42:33 2020 +0200
+++ b/src/pyams_content_es/shared/zmi/search.py	Mon Jul 20 12:33:08 2020 +0200
@@ -15,6 +15,7 @@
 """
 
 from elasticsearch_dsl import Q, Search
+from pyramid.decorator import reify
 from pyramid_es import get_client
 from z3c.form.browser.checkbox import SingleCheckBoxFieldWidget
 from zope.dublincore.interfaces import IZopeDublinCore
@@ -72,6 +73,10 @@
         fields['fulltext'].widgetFactory = SingleCheckBoxFieldWidget
         return fields
 
+    @reify
+    def sort_results(self):
+        return not bool(self.request.params.get('search_form.widgets.query'))
+
 
 @adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolAdvancedSearchView),
                 provides=ISearchFormFactory)