chores: Add function params and remove unused imports
diff --git a/erpnext/e_commerce/website_item_indexing.py b/erpnext/e_commerce/website_item_indexing.py
index 8c0e074..134939c 100644
--- a/erpnext/e_commerce/website_item_indexing.py
+++ b/erpnext/e_commerce/website_item_indexing.py
@@ -1,16 +1,13 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
-from __future__ import unicode_literals
-
import frappe
from frappe.utils.redis_wrapper import RedisWrapper
from redisearch import (
- Client, AutoCompleter, Query,
+ Client, AutoCompleter,
Suggestion, IndexDefinition,
- TextField, TagField,
- Document
+ TextField, TagField
)
def make_key(key):
diff --git a/erpnext/templates/pages/product_search.py b/erpnext/templates/pages/product_search.py
index 732d8f9..d041cc0 100644
--- a/erpnext/templates/pages/product_search.py
+++ b/erpnext/templates/pages/product_search.py
@@ -60,9 +60,9 @@
return [get_item_for_list_in_html(r) for r in data]
@frappe.whitelist(allow_guest=True)
-def search(query):
+def search(query, limit=10, fuzzy_search=True):
if not query:
- # TODO: return top/recent searches
+ # TODO: return top searches
return []
red = frappe.cache()
@@ -71,7 +71,11 @@
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, fuzzy=len(query) > 4)
+ suggestions = ac.get_suggestions(
+ query,
+ num=limit,
+ fuzzy= fuzzy_search and len(query) > 4 # Fuzzy on length < 3 can be real slow
+ )
# Build a query
query_string = query
@@ -86,6 +90,7 @@
results = client.search(q)
results = list(map(convert_to_dict, results.docs))
+ # FOR DEBUGGING
print("SEARCH RESULTS ------------------\n ", results)
return results
@@ -99,7 +104,7 @@
@frappe.whitelist(allow_guest=True)
def get_category_suggestions(query):
if not query:
- # TODO: return top/recent searches
+ # TODO: return top searches
return []
ac = AutoCompleter(make_key(WEBSITE_ITEM_CATEGORY_AUTOCOMPLETE), conn=frappe.cache())