From 6be44bf24703933e413c5821eb3ac903b1fcb686 Mon Sep 17 00:00:00 2001 From: Sandro Mani Date: Tue, 8 Oct 2024 10:32:40 +0200 Subject: [PATCH] Return empty result response if searchtext contains no tokens --- src/solr_search_service.py | 2 ++ src/trgm_search_service.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/solr_search_service.py b/src/solr_search_service.py index 8bc708f..9612ef2 100644 --- a/src/solr_search_service.py +++ b/src/solr_search_service.py @@ -43,6 +43,8 @@ def __init__(self, tenant, logger): def search(self, identity, searchtext, filter, limit): search_permissions = self.search_permissions(identity) (filterword, tokens) = self.tokenize(searchtext) + if not tokens: + return {'results': [], 'result_counts': []} filter_ids = filter if not filter: # use all permitted facets if filter is empty diff --git a/src/trgm_search_service.py b/src/trgm_search_service.py index 9451a7a..5f7345c 100644 --- a/src/trgm_search_service.py +++ b/src/trgm_search_service.py @@ -52,6 +52,8 @@ def __init__(self, tenant, logger): def search(self, identity, searchtext, filter, limit): (filterword, tokens) = self.tokenize(searchtext) + if not tokens: + return {'results': [], 'result_counts': [], 'layer_result_count': 0, 'feature_result_count': 0} if filterword: filter = [self.filterwords.get(filterword)]