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__