From 4c74e83c02cfcb72e634d67ba2701d527c05c9e6 Mon Sep 17 00:00:00 2001 From: Balamurali M Date: Mon, 14 Oct 2024 12:41:51 +0530 Subject: [PATCH] fix(HelpdeskSearch): Remove duplicates from results - Return results even if no nouns --- helpdesk/api/article.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/helpdesk/api/article.py b/helpdesk/api/article.py index 7e2f338c7..d7794e4ac 100644 --- a/helpdesk/api/article.py +++ b/helpdesk/api/article.py @@ -24,7 +24,8 @@ def search_with_enough_results(prev_res: list, query: str) -> tuple[list, bool]: out = hd_search(query, only_articles=True) if not out: return prev_res, len(prev_res) == NUM_RESULTS - items = (prev_res + out[0].get("items", []))[:NUM_RESULTS] + items = prev_res + out[0].get("items", []) + items = list({v["id"]: v for v in items}.values())[:NUM_RESULTS] # unique results return items, len(items) == NUM_RESULTS @@ -50,4 +51,5 @@ def search(query: str) -> list: if enough: return ret or_query = "|".join(nouns) - return search_with_enough_results(ret, or_query)[0] + ret, enough = search_with_enough_results(ret, or_query) + return ret