chores: Add function params and remove unused imports
This commit is contained in:
parent
4309239d6c
commit
c69de2d7a8
@ -1,16 +1,13 @@
|
|||||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.utils.redis_wrapper import RedisWrapper
|
from frappe.utils.redis_wrapper import RedisWrapper
|
||||||
|
|
||||||
from redisearch import (
|
from redisearch import (
|
||||||
Client, AutoCompleter, Query,
|
Client, AutoCompleter,
|
||||||
Suggestion, IndexDefinition,
|
Suggestion, IndexDefinition,
|
||||||
TextField, TagField,
|
TextField, TagField
|
||||||
Document
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def make_key(key):
|
def make_key(key):
|
||||||
|
|||||||
@ -60,9 +60,9 @@ def get_product_list(search=None, start=0, limit=12):
|
|||||||
return [get_item_for_list_in_html(r) for r in data]
|
return [get_item_for_list_in_html(r) for r in data]
|
||||||
|
|
||||||
@frappe.whitelist(allow_guest=True)
|
@frappe.whitelist(allow_guest=True)
|
||||||
def search(query):
|
def search(query, limit=10, fuzzy_search=True):
|
||||||
if not query:
|
if not query:
|
||||||
# TODO: return top/recent searches
|
# TODO: return top searches
|
||||||
return []
|
return []
|
||||||
|
|
||||||
red = frappe.cache()
|
red = frappe.cache()
|
||||||
@ -71,7 +71,11 @@ def search(query):
|
|||||||
|
|
||||||
ac = AutoCompleter(make_key(WEBSITE_ITEM_NAME_AUTOCOMPLETE), conn=red)
|
ac = AutoCompleter(make_key(WEBSITE_ITEM_NAME_AUTOCOMPLETE), conn=red)
|
||||||
client = Client(make_key(WEBSITE_ITEM_INDEX), 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
|
# Build a query
|
||||||
query_string = query
|
query_string = query
|
||||||
@ -86,6 +90,7 @@ def search(query):
|
|||||||
results = client.search(q)
|
results = client.search(q)
|
||||||
results = list(map(convert_to_dict, results.docs))
|
results = list(map(convert_to_dict, results.docs))
|
||||||
|
|
||||||
|
# FOR DEBUGGING
|
||||||
print("SEARCH RESULTS ------------------\n ", results)
|
print("SEARCH RESULTS ------------------\n ", results)
|
||||||
|
|
||||||
return results
|
return results
|
||||||
@ -99,7 +104,7 @@ def convert_to_dict(redis_search_doc):
|
|||||||
@frappe.whitelist(allow_guest=True)
|
@frappe.whitelist(allow_guest=True)
|
||||||
def get_category_suggestions(query):
|
def get_category_suggestions(query):
|
||||||
if not query:
|
if not query:
|
||||||
# TODO: return top/recent searches
|
# TODO: return top searches
|
||||||
return []
|
return []
|
||||||
|
|
||||||
ac = AutoCompleter(make_key(WEBSITE_ITEM_CATEGORY_AUTOCOMPLETE), conn=frappe.cache())
|
ac = AutoCompleter(make_key(WEBSITE_ITEM_CATEGORY_AUTOCOMPLETE), conn=frappe.cache())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user