Commit 1faad256 authored by lixiaofang's avatar lixiaofang

add

parent 2de1926e
......@@ -178,9 +178,9 @@ class QueryWordAttr(object):
def get_search_query_results_num(cls, name):
try:
total_num = 0
data = StrategyHistoryQueryWords.objects.filter(keyword=name,search_num__lte=7).values("answer_num",
"tractate_num",
"diary_num").first()
data = StrategyHistoryQueryWords.objects.filter(keyword=name, search_num__lte=7).values("answer_num",
"tractate_num",
"diary_num").first()
if data:
for value in data.values():
......@@ -190,6 +190,48 @@ class QueryWordAttr(object):
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return 0
@classmethod
def save_query_to_redis(cls, query, from_type=None):
try:
lower_query = str(query).lower()
key = "save_query_to_redis"
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)
else:
order_weight = cls.get_project_query_word_weight(name=query)
search_num = cls.get_query_results_num(name=query)
if redis_data:
json_data = json.loads(redis_data)
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}))
return True
else:
return False
else:
return False
else:
redis_client.hset(key, lower_query,
json.dumps({"order_weight": order_weight, "search_num": search_num}))
return True
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return False
from gm_rpcd.all import bind
from libs.cache import redis_client
......
......@@ -35,8 +35,11 @@ class Command(BaseCommand):
es_cli = ESPerform.get_cli()
type_name1 = "suggest-v1"
type_name = "suggest"
type_name2 = "suggest-v2"
type_name3 = "suggest-v3"
if len(options["type"]):
if options["type"] == "all" or type_name == options["type"] or type_name1 == options["type"]:
if options["type"] == "all" or type_name == options["type"] or type_name1 == options["type"] or type_name2 == options['type'] or type_name3 == options['type']:
type_name = options["type"]
official_index_name = ESPerform.get_official_index_name(type_name)
index_exists = es_cli.indices.exists(official_index_name)
......
{
"dynamic":"strict",
"properties": {
"id":{"type":"text"},
"suggest":{
"analyzer":"keyword",
"search_analyzer":"keyword",
"type":"completion",
"contexts":[
{
"name":"is_online",
"type": "category"
}
]
},
"suggest_type":{"type":"long"},//0-汉字,1-汉字全拼,2-拼音,3-拼音全拼,4-拼音简写,5-拼音简写全拼
"tips_name_type":{"type":"long"},//tips数据所属类型,0-tag,1-hospital,2-doctor,3-wiki
"ori_name":{"type":"keyword"},//原名称
"order_weight":{"type":"double"},//订单权重
"offline_score":{"type":"double"},//离线分
"results_num":{"type":"integer"},//结果数量
"type_flag":{"type":"keyword"},
"is_online":{"type":"boolean"}//上线
}
}
{
"dynamic":"strict",
"properties": {
"id":{"type":"text"},
"suggest":{
"analyzer":"keyword",
"search_analyzer":"keyword",
"type":"completion",
"contexts":[
{
"name":"is_online",
"type": "category"
}
]
},
"suggest_type":{"type":"long"},//0-汉字,1-汉字全拼,2-拼音,3-拼音全拼,4-拼音简写,5-拼音简写全拼
"tips_name_type":{"type":"long"},//tips数据所属类型,0-tag,1-hospital,2-doctor,3-wiki
"ori_name":{"type":"keyword"},//原名称
"order_weight":{"type":"double"},//订单权重
"offline_score":{"type":"double"},//离线分
"results_num":{"type":"integer"},//结果数量
"type_flag":{"type":"keyword"},
"is_online":{"type":"boolean"}//上线
}
}
......@@ -94,7 +94,6 @@ class DoctorTransfer(object):
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_doctor_query_word_weight(instance.name)
item_dict["results_num"] = QueryWordAttr.get_query_results_num(instance.name)
item_dict["type_flag"] = get_tips_word_type(str(instance.name).lower())
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import traceback
import traceback, re
from libs.tools import getMd5Digest
from trans2es.commons.words_utils import QueryWordAttr, get_tips_word_type
from trans2es.commons.commons import get_tips_suggest_list_v1
......@@ -16,22 +16,23 @@ class SearchWord(object):
try:
ret_list = list()
item_dict = dict()
item_dict["id"] = getMd5Digest(str(instance.keyword))
item_dict["ori_name"] = instance.keyword
is_online = False
if QueryWordAttr.get_search_query_results_num(instance.keyword):
sub_query = re.sub('\W+', '', instance.keyword)
keyword = str(sub_query).lower()
item_dict["id"] = getMd5Digest(keyword)
item_dict["ori_name"] = keyword
if QueryWordAttr.get_search_query_results_num(keyword):
is_online = False if instance.is_delete else True
else:
is_online = False
item_dict["is_online"] = is_online
item_dict["order_weight"] = QueryWordAttr.get_hot_search_query_word_weight(instance.keyword)
item_dict["results_num"] = QueryWordAttr.get_search_query_results_num(instance.keyword)
item_dict["type_flag"] = get_tips_word_type(instance.keyword)
item_dict["order_weight"] = QueryWordAttr.get_hot_search_query_word_weight(keyword)
item_dict["results_num"] = QueryWordAttr.get_search_query_results_num(keyword)
item_dict["type_flag"] = get_tips_word_type(keyword)
item_dict["offline_score"] = 0.0
item_dict["tips_name_type"] = 5
ret_list.append(item_dict)
suggest_list = get_tips_suggest_list_v1(str(instance.keyword).lower())
suggest_list = get_tips_suggest_list_v1(keyword)
return (item_dict, suggest_list)
except:
......
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