From 70b164e7dd62a7e2b600ba39fc3027f18108c385 Mon Sep 17 00:00:00 2001 From: Hussain Nagaria Date: Mon, 3 May 2021 05:47:38 +0530 Subject: [PATCH] chore: Add query clean-up --- erpnext/templates/pages/product_search.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/erpnext/templates/pages/product_search.py b/erpnext/templates/pages/product_search.py index b004f80781..c6f04dff09 100644 --- a/erpnext/templates/pages/product_search.py +++ b/erpnext/templates/pages/product_search.py @@ -67,6 +67,8 @@ def search(query): red = frappe.cache() + query = clean_up_query(query) + ac = AutoCompleter(make_key(WEBSITE_ITEM_NAME_AUTOCOMPLETE), conn=red) client = Client(make_key(WEBSITE_ITEM_INDEX), conn=red) suggestions = ac.get_suggestions(query, num=10) @@ -75,7 +77,7 @@ def search(query): query_string = query for s in suggestions: - query_string += f"|('{s.string}')" + query_string += f"|('{clean_up_query(s.string)}')" q = Query(query_string) @@ -88,6 +90,9 @@ def search(query): return results +def clean_up_query(query): + return ''.join(c for c in query if c.isalnum() or c.isspace()) + def convert_to_dict(redis_search_doc): return redis_search_doc.__dict__