From 0c71c536e503b0d77d7bea057370c49ec00f5225 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Thu, 29 Sep 2022 16:38:27 +0530 Subject: Hard-limit the number of search results. * wqflask/wqflask/gsearch.py (MAX_SEARCH_RESULTS): New constant. (GSearch.__init__): Hard-limit the number of search results to MAX_SEARCH_RESULTS. --- wqflask/wqflask/gsearch.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/wqflask/wqflask/gsearch.py b/wqflask/wqflask/gsearch.py index f2ee1826..ee1291be 100644 --- a/wqflask/wqflask/gsearch.py +++ b/wqflask/wqflask/gsearch.py @@ -10,6 +10,9 @@ from utility.authentication_tools import check_resource_availability from utility.monads import MonadicDict from wqflask.database import xapian_database +# KLUDGE: Due to the lack of pagination, we hard-limit the maximum +# number of search results. +MAX_SEARCH_RESULTS = 1000 def is_permitted_for_listing(trait, search_type): """Check if it is permissible to list trait in search results.""" @@ -66,7 +69,7 @@ class GSearch: query, xapian.Query(f"XT{self.type}"))) for i, trait in enumerate( - [trait for xapian_match in enquire.get_mset(0, db.get_doccount()) + [trait for xapian_match in enquire.get_mset(0, MAX_SEARCH_RESULTS) if is_permitted_for_listing( trait := MonadicDict(json.loads(xapian_match.document.get_data())), search_type=self.type)]): -- cgit v1.2.3