From 9e80c6c9843406178f54d5d4cbb4f605ec2a0c83 Mon Sep 17 00:00:00 2001 From: Ashwini Sukale Date: Thu, 19 Sep 2024 11:10:51 +0530 Subject: [PATCH] Added default sort for organization api on id field --- rorapi/common/es_utils.py | 3 +++ rorapi/common/queries.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/rorapi/common/es_utils.py b/rorapi/common/es_utils.py index 0ec5f1e..cb3765b 100644 --- a/rorapi/common/es_utils.py +++ b/rorapi/common/es_utils.py @@ -82,3 +82,6 @@ def paginate(self, page): def get_query(self): return self.search + + def add_sort(self, field, order="asc"): + self.search = self.search.sort({field: {"order": order}}) \ No newline at end of file diff --git a/rorapi/common/queries.py b/rorapi/common/queries.py index 6371d9d..23c47b7 100644 --- a/rorapi/common/queries.py +++ b/rorapi/common/queries.py @@ -335,6 +335,10 @@ def build_search_query(params, version): ] ) + sort_field = params.get("sort", "id") + sort_order = params.get("order", "asc") + qb.add_sort(sort_field, sort_order) + qb.paginate(int(params.get("page", 1))) return qb.get_query()