Commit 23499ff6 authored by lixiaofang's avatar lixiaofang

add;

parent 1faad256
......@@ -191,12 +191,11 @@ class QueryWordAttr(object):
return 0
@classmethod
def save_query_to_redis(cls, query, from_type=None):
def save_query_to_redis(cls, query, from_type=None, get_ret=False):
try:
lower_query = str(query).lower()
key = "save_query_to_redis"
key = "】】】】】】】】】】】】】】"
redis_data = redis_client.hget(key, lower_query)
if from_type == "search_query":
order_weight = cls.get_hot_search_query_word_weight(name=query)
search_num = cls.get_search_query_results_num(name=query)
......@@ -209,28 +208,30 @@ class QueryWordAttr(object):
have_save_order_weight = json_data.get('order_weight', 0)
have_save_search_num = json_data.get('order_weight', 0)
if have_save_order_weight < order_weight:
redis_client.hset(key, lower_query,
json.dumps({"order_weight": order_weight, "search_num": search_num}))
return True
elif redis_data == order_weight:
if have_save_search_num < search_num:
redis_client.hset(key, lower_query,
json.dumps({"order_weight": order_weight, "search_num": search_num}))
if get_ret:
if have_save_order_weight == order_weight and have_save_search_num == search_num:
return True
else:
return False
else:
return False
else:
if have_save_order_weight < order_weight or (
have_save_order_weight == order_weight and have_save_search_num < search_num):
logging.log(
"query:%s,have_save_order_weight:%s,have_save_search_num:%s,order_weight:%s,search_num:%s" % (
query, have_save_order_weight, have_save_search_num, order_weight, search_num))
redis_client.hset(key, lower_query,
json.dumps({"order_weight": order_weight, "search_num": search_num}))
else:
pass
elif get_ret == False:
redis_client.hset(key, lower_query,
json.dumps({"order_weight": order_weight, "search_num": search_num}))
return True
else:
pass
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return False
from gm_rpcd.all import bind
......
......@@ -10,7 +10,7 @@ from libs.cache import redis_client
import json
from django.conf import settings
from trans2es.commons.commons import get_tips_suggest_list,get_tips_suggest_list_v1
from trans2es.commons.commons import get_tips_suggest_list, get_tips_suggest_list_v1
from trans2es.commons.words_utils import QueryWordAttr, get_tips_word_type
......@@ -20,6 +20,7 @@ class ItemWikiTransfer(object):
def get_wiki_data_name_mapping_results_to_redis(cls, instance):
try:
wiki_name = instance.name.strip()
QueryWordAttr.save_query_to_redis(wiki_name, from_type="wiki")
if wiki_name:
multi_fields = {
'name': 1,
......@@ -83,23 +84,21 @@ class ItemWikiTransfer(object):
def get_itemwiki_suggest_data_list(cls, instance):
try:
ret_list = list()
item_dict = dict()
item_dict["id"] = getMd5Digest(str(instance.name))
item_dict["ori_name"] = instance.name
item_dict["is_online"] = instance.is_online
item_dict["order_weight"] = QueryWordAttr.get_project_query_word_weight(instance.name)
item_dict["results_num"] = QueryWordAttr.get_query_results_num(instance.name)
item_dict["type_flag"] = get_tips_word_type(instance.name)
item_dict["offline_score"] = 0.0
item_dict["tips_name_type"] = 3
ret_list.append(item_dict)
suggest_list = get_tips_suggest_list(str(instance.name).lower())
logging.info("get suggest_list:%s" % suggest_list)
suggest_list = list()
ret_bol = QueryWordAttr.save_query_to_redis(query=str(instance.name), from_type="wiki", get_ret=True)
if ret_bol:
item_dict["id"] = getMd5Digest(str(instance.name))
item_dict["ori_name"] = instance.name
item_dict["is_online"] = instance.is_online
item_dict["order_weight"] = QueryWordAttr.get_project_query_word_weight(instance.name)
item_dict["results_num"] = QueryWordAttr.get_query_results_num(instance.name)
item_dict["type_flag"] = get_tips_word_type(instance.name)
item_dict["offline_score"] = 0.0
item_dict["tips_name_type"] = 3
ret_list.append(item_dict)
suggest_list = get_tips_suggest_list(str(instance.name).lower())
logging.info("get suggest_list:%s" % suggest_list)
return (item_dict, suggest_list)
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment