Commit ca099d92 authored by lixiaofang's avatar lixiaofang

add

parent 646fcb3d
......@@ -6,6 +6,7 @@ import logging
import traceback
import json
import base64
import hashlib
from libs.es import ESPerform
from libs.cache import redis_client
from libs.tools import g_hospital_pos_dict
......@@ -14,78 +15,10 @@ from gm_rpcd.all import bind
from trans2es.commons.words_utils import QueryWordAttr, get_tips_word_type
def get_suggest_tips(query, lat, lng, offset=0, size=50):
def get_suggest_tips(query, lat, lng, offset=0, size=50, device_id=None):
try:
###先获取完全命中的query
# qq = {
# "query": {
# "bool": {
# "must": [{
# "term": {
# "ori_name": query
# }
# }, {
# "term": {
# "is_online": True
# }
# }]
# }
# }
# }
# logging.info("get qqqqqqqqq:%s" % qq)
# whole_query = ESPerform.get_search_results(ESPerform.get_cli(), sub_index_name="suggest", query_body=qq,
# offset=0, size=1, is_suggest_request=True)
#
# logging.info("get whole_query:%s" % whole_query)
# hits = whole_query["hits"]["hits"]
#
# for item in hits:
# have_read_tips_set.add(item["_source"]["ori_name"])
# id = item["_source"]["id"]
# ori_name = item["_source"]["ori_name"]
# results_num = item["_source"]["results_num"]
# is_online = item["_source"]["is_online"]
# offline_score = item["_source"]["offline_score"]
# type_flag = item["_source"]["type_flag"]
#
# highlight_marks = u'<ems>%s</ems>' % query
# item["_source"]["highlight_name"] = item["_source"]["ori_name"].replace(query, highlight_marks)
# highlight_name = item["_source"]["highlight_name"]
# if item["_source"]["type_flag"] == "hospital":
# if lat is not None and lng is not None and lat != 0.0 and lng != 0.0:
#
# logging.info("get g_hospital_pos_dict:%s" % g_hospital_pos_dict)
# if item["_source"]["ori_name"] in g_hospital_pos_dict:
# distance = point_distance(lng, lat,
# g_hospital_pos_dict[item["_source"]["ori_name"]][0],
# g_hospital_pos_dict[item["_source"]["ori_name"]][1])
# if distance < 1000 * 50:
# if distance < 1000:
# if distance < 100:
# item["_source"]["describe"] = "<100" + "米"
# else:
# item["_source"]["describe"] = "约" + str(int(distance)) + "米"
# else:
# item["_source"]["describe"] = "约" + str(
# round(1.0 * distance / 1000, 1)) + "km"
# else:
# item["_source"]["describe"] = ">50km"
# else:
# item["_source"]["describe"] = ""
#
# else:
# item["_source"]["describe"] = ""
# else:
# if item["_source"]["type_flag"] == "doctor":
# item["_source"]["describe"] = ""
# else:
# item["_source"]["describe"] = "约" + str(item["_source"]["results_num"]) + "个结果" if \
# item["_source"]["results_num"] else ""
#
# ret_list.append({"offline_score": offline_score, "ori_name": ori_name, "results_num": results_num, "id": id,
# "highlight_name": highlight_name, "type_flag": type_flag,
# "is_online": is_online})
###加两层灰度
###获取联想到的数据
# ios输入法在某些情况下会携带\\u2006
......@@ -262,3 +195,23 @@ def set_highlihgt(query=None, ori_name=None):
highlight_name = high_query
return highlight_name
def recommed_service_category_device_id(device_id, real_cary=False):
try:
'''
设备品类显示, 是否命中灰度
'''
categroy_select_cary = ["0", "1", "2", "3", "4", "a", "b", "c"]
if not device_id:
return False
hd_id = hashlib.md5(str(device_id).encode()).hexdigest()
is_gray = hd_id[-1] in categroy_select_cary
if not is_gray:
gray_devices_key = "gm:gray:devices:key"
return redis_client.sismember(gray_devices_key, device_id)
return is_gray
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return False
......@@ -13,7 +13,7 @@ from search.utils.auto_tips import get_suggest_tips
@bind("search_tips/search/auto_complete_query")
def auto_complete_query(q, lat, lng):
def auto_complete_query(q, lat, lng, device_id=None):
try:
"""auto complate words/tags/doctors etc.
......@@ -28,7 +28,7 @@ def auto_complete_query(q, lat, lng):
# if not q:
# return json_http_response({'error': 0, 'data': []})
data = get_suggest_tips(q, float(lat), float(lng))
data = get_suggest_tips(q, float(lat), float(lng), device_id=device_id)
result = {
'error': 0,
......
......@@ -17,6 +17,7 @@ def uuid4():
"""
return uuid.uuid4().hex
def get_tips_suggest_list(instance_cn_name):
try:
# ch_full_weight = 6.0 * 1000
......@@ -113,3 +114,101 @@ def get_tips_suggest_list(instance_cn_name):
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return list()
def get_tips_suggest_list_v1(instance_cn_name):
try:
# ch_full_weight = 6.0 * 1000
# py_full_weight = 3.0 * 1000
full_weight = 3.0 * 1000
py_acronym_full_weight = 3.0 * 1000
py_acronym_prefix_weight = 2
ch_prefix_weight = 1.5
py_prefix_weight = 1.0
# 命中开始部分加权
begin_prefix_weight = 1
ch_full_word = instance_cn_name.strip()
py_full_word = ''.join(lazy_pinyin(ch_full_word))
py_acronym_full_word = ''.join(lazy_pinyin(ch_full_word, style=pypinyin.FIRST_LETTER))
suggest_dict = dict()
cur_index = 0
# 中文
for i in range(len(ch_full_word)):
ch_name_term = ch_full_word[i:].strip()
if ch_name_term and ch_full_word[i] != "(" and ch_full_word[i] != ")":
prefix_weight = ch_prefix_weight if len(ch_name_term) != len(ch_full_word) else full_weight
suggest_type = 0 if len(ch_name_term) != len(ch_full_word) else 1
term_begin_prefix_weight = begin_prefix_weight if i == 0 else 1.0
suggest_item = {
"input": [ch_name_term],
"word_weight": (1.0 * len(ch_name_term) / len(
(ch_full_word))) * prefix_weight * term_begin_prefix_weight,
"suggest_type": suggest_type
}
if ch_name_term[0] not in suggest_dict:
cur_index += 1
suggest_item["cur_index"] = cur_index
suggest_dict[ch_name_term[0]] = suggest_item
else:
suggest_dict[ch_name_term[0]]["input"].append(ch_name_term)
if suggest_item["word_weight"] > suggest_dict[ch_name_term[0]]["word_weight"]:
suggest_dict[ch_name_term[0]]["word_weight"] = suggest_item["word_weight"]
suggest_dict[ch_name_term[0]]["suggest_type"] = suggest_item["suggest_type"]
# 拼音
if py_full_word != ch_full_word:
for i in range(len(py_full_word)):
py_name_term = py_full_word[i:].strip()
if py_name_term and py_full_word[i] != "(" and py_full_word[i] != ")":
prefix_weight = py_prefix_weight if len(py_name_term) != len(py_full_word) else full_weight
suggest_type = 2 if len(py_name_term) != len(py_full_word) else 3
term_begin_prefix_weight = begin_prefix_weight if i == 0 else 1.0
suggest_item = {
"input": [py_name_term],
"word_weight": (1.0 * len(py_name_term) / len(
py_full_word)) * prefix_weight * term_begin_prefix_weight,
"suggest_type": suggest_type
}
if py_name_term[0] not in suggest_dict:
cur_index += 1
suggest_item["cur_index"] = cur_index
suggest_dict[py_name_term[0]] = suggest_item
else:
suggest_dict[py_name_term[0]]["input"].append(py_name_term)
if suggest_item["word_weight"] > suggest_dict[py_name_term[0]]["word_weight"]:
suggest_dict[py_name_term[0]]["word_weight"] = suggest_item["word_weight"]
suggest_dict[py_name_term[0]]["suggest_type"] = suggest_item["suggest_type"]
# 简写
if py_acronym_full_word != py_full_word:
for i in range(len(py_acronym_full_word)):
py_acronym_term = py_acronym_full_word[i:].strip()
if py_acronym_term and py_acronym_full_word[i] != "(" and py_acronym_full_word[i] != ")":
prefix_weight = py_acronym_prefix_weight if len(py_acronym_term) != len(
py_acronym_full_word) else py_acronym_full_weight
suggest_type = 4 if len(py_acronym_term) != len(py_acronym_full_word) else 5
term_begin_prefix_weight = begin_prefix_weight if i == 0 else 1.0
suggest_item = {
"input": [py_acronym_term],
"word_weight": (1.0 * len(py_acronym_term) / len(
py_acronym_full_word)) * prefix_weight * term_begin_prefix_weight,
"suggest_type": suggest_type
}
if py_acronym_term[0] not in suggest_dict:
cur_index += 1
suggest_item["cur_index"] = cur_index
suggest_dict[py_acronym_term[0]] = suggest_item
else:
suggest_dict[py_acronym_term[0]]["input"].append(py_acronym_term)
if suggest_item["word_weight"] > suggest_dict[py_acronym_term[0]]["word_weight"]:
suggest_dict[py_acronym_term[0]]["word_weight"] = suggest_item["word_weight"]
suggest_dict[py_acronym_term[0]]["suggest_type"] = suggest_item["suggest_type"]
return suggest_dict.values()
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return list()
......@@ -14,13 +14,13 @@ import sys
import copy
from trans2es.models import doctor, itemwiki, collectwiki, brandwiki, productwiki, tag, wordresemble
from trans2es.utils.doctor_transfer import DoctorTransfer
from trans2es.utils.hospital_transfer import HospitalTransfer
from trans2es.utils.itemwiki_transfer import ItemWikiTransfer
from trans2es.utils.collectwiki_transfer import CollectWikiTransfer
from trans2es.utils.brandwiki_transfer import BrandWikiTransfer
from trans2es.utils.productwiki_transfer import ProduceWikiTransfer
from trans2es.utils.tag_transfer import TagTransfer
from trans2es.utils.doctor_transfer import DoctorTransfer, DoctorTransferV1
from trans2es.utils.hospital_transfer import HospitalTransfer, HospitalTransferV1
from trans2es.utils.itemwiki_transfer import ItemWikiTransfer, ItemWikiTransferV1
from trans2es.utils.collectwiki_transfer import CollectWikiTransfer, CollectWikiTransferV1
from trans2es.utils.brandwiki_transfer import BrandWikiTransfer, BrandWikiTransferV1
from trans2es.utils.productwiki_transfer import ProduceWikiTransfer, ProduceWikiTransferV1
from trans2es.utils.tag_transfer import TagTransfer, TagTransferV1
from trans2es.utils.wordresemble import WordResemble
from libs.es import ESPerform
from libs.tools import tzlc, getMd5Digest
......@@ -286,7 +286,8 @@ def get_type_info_map():
name='suggest',
type='doctor_tips', # doctor
model=doctor.Doctor,
query_deferred=lambda: doctor.Doctor.objects.all().filter(doctor_type__in=[DOCTOR_TYPE.DOCTOR,DOCTOR_TYPE.OFFICER]).query,
query_deferred=lambda: doctor.Doctor.objects.all().filter(
doctor_type__in=[DOCTOR_TYPE.DOCTOR, DOCTOR_TYPE.OFFICER]).query,
get_data_func=DoctorTransfer.get_doctor_suggest_data_list,
bulk_insert_chunk_size=100,
round_insert_chunk_size=5,
......@@ -365,89 +366,90 @@ def get_type_info_map():
round_insert_chunk_size=5,
round_insert_period=2,
),
# TypeInfo(
# name='suggest-v1',
# type='doctor_tips', # doctor
# model=doctor.Doctor,
# query_deferred=lambda: doctor.Doctor.objects.all().filter(doctor_type=DOCTOR_TYPE.DOCTOR).query,
# get_data_func=DoctorTransfer.get_doctor_suggest_data_list,
# bulk_insert_chunk_size=100,
# round_insert_chunk_size=5,
# round_insert_period=2,
# ),
# TypeInfo(
# name='suggest-v1',
# type='hospital_tips', # hospital
# model=doctor.Hospital,
# # query_deferred=lambda: doctor.Doctor.objects.all().filter(doctor_type=DOCTOR_TYPE.OFFICER).query,
# query_deferred=lambda: doctor.Hospital.objects.all().query,
# get_data_func=HospitalTransfer.get_hospital_suggest_data_list,
# bulk_insert_chunk_size=100,
# round_insert_chunk_size=5,
# round_insert_period=2,
# ),
# TypeInfo(
# name='suggest-v1',
# type='itemwiki_tips', # itemwiki
# model=itemwiki.ItemWiki,
# query_deferred=lambda: itemwiki.ItemWiki.objects.all().query,
# get_data_func=ItemWikiTransfer.get_itemwiki_suggest_data_list,
# bulk_insert_chunk_size=100,
# round_insert_chunk_size=5,
# round_insert_period=2,
# ),
# TypeInfo(
# name='suggest-v1',
# type='collectwiki_tips', # collectwiki
# model=collectwiki.CollectWiki,
# query_deferred=lambda: collectwiki.CollectWiki.objects.all().query,
# get_data_func=CollectWikiTransfer.get_collectwiki_suggest_data_list,
# bulk_insert_chunk_size=100,
# round_insert_chunk_size=5,
# round_insert_period=2,
# ),
# TypeInfo(
# name='suggest-v1',
# type='brandwiki_tips', # brandwiki
# model=brandwiki.BrandWiki,
# query_deferred=lambda: brandwiki.BrandWiki.objects.all().query,
# get_data_func=BrandWikiTransfer.get_brandwiki_suggest_data_list,
# bulk_insert_chunk_size=100,
# round_insert_chunk_size=5,
# round_insert_period=2,
# ),
# TypeInfo(
# name='suggest-v1',
# type='productwiki_tips', # productwiki
# model=productwiki.ProductWiki,
# query_deferred=lambda: productwiki.ProductWiki.objects.all().query,
# get_data_func=ProduceWikiTransfer.get_productwiki_suggest_data_list,
# bulk_insert_chunk_size=100,
# round_insert_chunk_size=5,
# round_insert_period=2,
# ),
# TypeInfo(
# name='suggest-v1',
# type='tag_tips', # tag
# model=tag.Tag,
# query_deferred=lambda: tag.Tag.objects.all().filter(
# tag_type__in=[TAG_TYPE.BODY_PART, TAG_TYPE.BODY_PART_SUB_ITEM, TAG_TYPE.ITEM_WIKI]).query,
# get_data_func=TagTransfer.get_tag_suggest_data_list,
# bulk_insert_chunk_size=100,
# round_insert_chunk_size=5,
# round_insert_period=2,
# ),
# TypeInfo(
# name='suggest-v1',
# type='wordrel_tips', # tag
# model=wordresemble.WordRel,
# query_deferred=lambda: wordresemble.WordRel.objects.filter(
# category__in=[13, 12, 11, 9, 1]).query,
# get_data_func=WordResemble.get_resemble_list,
# bulk_insert_chunk_size=100,
# round_insert_chunk_size=5,
# round_insert_period=2,
# )
TypeInfo(
name='suggest-v1',
type='doctor_tips', # doctor
model=doctor.Doctor,
query_deferred=lambda: doctor.Doctor.objects.all().filter(
doctor_type__in=[DOCTOR_TYPE.DOCTOR, DOCTOR_TYPE.OFFICER]).query,
get_data_func=DoctorTransfer.get_doctor_suggest_data_list,
bulk_insert_chunk_size=100,
round_insert_chunk_size=5,
round_insert_period=2,
),
TypeInfo(
name='suggest-v1',
type='hospital_tips-v1', # hospital
model=doctor.Hospital,
# query_deferred=lambda: doctor.Doctor.objects.all().filter(doctor_type=DOCTOR_TYPE.OFFICER).query,
query_deferred=lambda: doctor.Hospital.objects.all().query,
get_data_func=HospitalTransferV1.get_hospital_suggest_data_list,
bulk_insert_chunk_size=100,
round_insert_chunk_size=5,
round_insert_period=2,
),
TypeInfo(
name='suggest-v1',
type='itemwiki_tips-v1', # itemwiki
model=itemwiki.ItemWiki,
query_deferred=lambda: itemwiki.ItemWiki.objects.all().query,
get_data_func=ItemWikiTransferV1.get_itemwiki_suggest_data_list,
bulk_insert_chunk_size=100,
round_insert_chunk_size=5,
round_insert_period=2,
),
TypeInfo(
name='suggest-v1',
type='collectwiki_tips-v1', # collectwiki
model=collectwiki.CollectWiki,
query_deferred=lambda: collectwiki.CollectWiki.objects.all().query,
get_data_func=CollectWikiTransferV1.get_collectwiki_suggest_data_list,
bulk_insert_chunk_size=100,
round_insert_chunk_size=5,
round_insert_period=2,
),
TypeInfo(
name='suggest-v1',
type='brandwiki_tips-v1', # brandwiki
model=brandwiki.BrandWiki,
query_deferred=lambda: brandwiki.BrandWiki.objects.all().query,
get_data_func=BrandWikiTransferV1.get_brandwiki_suggest_data_list,
bulk_insert_chunk_size=100,
round_insert_chunk_size=5,
round_insert_period=2,
),
TypeInfo(
name='suggest-v1',
type='productwiki_tips-v1', # productwiki
model=productwiki.ProductWiki,
query_deferred=lambda: productwiki.ProductWiki.objects.all().query,
get_data_func=ProduceWikiTransferV1.get_productwiki_suggest_data_list,
bulk_insert_chunk_size=100,
round_insert_chunk_size=5,
round_insert_period=2,
),
TypeInfo(
name='suggest-v1',
type='tag_tips-v1', # tag
model=tag.Tag,
query_deferred=lambda: tag.Tag.objects.all().filter(
tag_type__in=[TAG_TYPE.BODY_PART, TAG_TYPE.BODY_PART_SUB_ITEM, TAG_TYPE.ITEM_WIKI]).query,
get_data_func=TagTransferV1.get_tag_suggest_data_list,
bulk_insert_chunk_size=100,
round_insert_chunk_size=5,
round_insert_period=2,
),
TypeInfo(
name='suggest-v1',
type='wordrel_tips-v1', # tag
model=wordresemble.WordRel,
query_deferred=lambda: wordresemble.WordRel.objects.filter(
category__in=[13, 12, 11, 9, 1]).query,
get_data_func=WordResemble.get_resemble_list,
bulk_insert_chunk_size=100,
round_insert_chunk_size=5,
round_insert_period=2,
)
]
type_info_map = {
......@@ -550,7 +552,7 @@ def tips_attr_sync_to_redis_type_info_map():
TypeInfo(
name='suggest',
type='wordresemble_results_num', # api_wordrelresemble
model= wordresemble.WordRel,
model=wordresemble.WordRel,
query_deferred=lambda: wordresemble.WordRel.objects.filter(
category__in=[13, 12, 11, 9, 1]).query,
get_data_func=WordResemble.set_data_to_redis,
......
......@@ -4,13 +4,13 @@ import os
import sys
import logging
import traceback
from libs.tools import tzlc,getMd5Digest
from libs.tools import tzlc, getMd5Digest
from libs.es import ESPerform
from libs.cache import redis_client
import json
from trans2es.commons.commons import get_tips_suggest_list
from trans2es.commons.words_utils import QueryWordAttr,get_tips_word_type
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
class BrandWikiTransfer(object):
......@@ -35,7 +35,35 @@ class BrandWikiTransfer(object):
suggest_list = get_tips_suggest_list(instance.name)
return (item_dict,suggest_list)
return (item_dict, suggest_list)
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return ([],[])
\ No newline at end of file
return ([], [])
class BrandWikiTransferV1(object):
@classmethod
def get_brandwiki_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_v1(instance.name)
return (item_dict, suggest_list)
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return ([], [])
......@@ -4,13 +4,13 @@ import os
import sys
import logging
import traceback
from libs.tools import tzlc,getMd5Digest
from libs.tools import tzlc, getMd5Digest
from libs.es import ESPerform
from libs.cache import redis_client
import json
from trans2es.commons.commons import get_tips_suggest_list
from trans2es.commons.words_utils import QueryWordAttr,get_tips_word_type
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
class CollectWikiTransfer(object):
......@@ -35,7 +35,35 @@ class CollectWikiTransfer(object):
suggest_list = get_tips_suggest_list(instance.name)
return (item_dict,suggest_list)
return (item_dict, suggest_list)
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return ([],[])
\ No newline at end of file
return ([], [])
class CollectWikiTransferV1(object):
@classmethod
def get_collectwiki_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_v1(instance.name)
return (item_dict, suggest_list)
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return ([], [])
......@@ -109,3 +109,100 @@ class DoctorTransfer(object):
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return (dict(), list())
class DoctorTransferV1(object):
@classmethod
def get_doctor_data_name_mapping_results_to_redis(cls, instance):
try:
doctor_name = instance.name.strip()
if doctor_name:
multi_fields = {
'hospital.city_province_name': 1,
'hospital.name': 1,
'name': 1,
'hospital.city_name': 1,
'hospital.officer_name': 1,
'service_closure_tags': 1
}
query_fields = ['^'.join((k, str(v))) for (k, v) in multi_fields.items()]
multi_match = {
'query': doctor_name,
'type': 'cross_fields',
'operator': 'and',
'fields': query_fields,
}
q = {
"size": 0,
"query": {
"bool": {
"should": [
{"multi_match": multi_match}
],
"must": [
{"term": {"is_online": True}}
],
"minimum_should_match": 1
}
}
}
result_dict = ESPerform.get_search_results(ESPerform.get_cli(settings.GM_ORI_ES_INFO_LIST),
sub_index_name="doctor", doc_type="doctor", query_body=q,
offset=0, size=0)
doctor_results = result_dict["total_count"]
redis_key_prefix = "search_tips:tips_mapping_num"
redis_data = redis_client.hget(redis_key_prefix, doctor_name)
redis_val_dict = json.loads(str(redis_data, encoding="utf-8")) if redis_data else {}
total_count = doctor_results
if 't' in redis_val_dict:
total_count += int(redis_val_dict['t'])
redis_val_dict['t'] = total_count
redis_val_dict['d'] = doctor_results
logging.info(
"duan add,redis_key_prefix:%s,redis_val_dict:%s" % (str(redis_key_prefix), str(redis_val_dict)))
redis_client.hset(redis_key_prefix, doctor_name, json.dumps(redis_val_dict))
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
@classmethod
def get_doctor_suggest_data_list(cls, instance):
try:
ret_list = list()
keyword = instance.name
cut_bool = False
cut_word = ["下线", "停用", "已经下线", "账号停用"]
for i in cut_word:
if keyword.find(i) >= 0:
cut_bool = True
item_dict = dict()
suggest_list = list()
if cut_bool == False:
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(instance.name)
item_dict["offline_score"] = 0.0
item_dict["tips_name_type"] = 2
ret_list.append(item_dict)
suggest_list = get_tips_suggest_list(instance.name)
return (item_dict, suggest_list)
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return (dict(), list())
......@@ -9,7 +9,7 @@ from libs.es import ESPerform
from libs.cache import redis_client
import json
from trans2es.commons.commons import get_tips_suggest_list
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
......@@ -62,3 +62,54 @@ class HospitalTransfer(object):
redis_client.hset(redis_key_prefix, name, pos_list)
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
class HospitalTransferV1(object):
@classmethod
def get_hospital_suggest_data_list(cls, instance):
try:
ret_list = list()
name = instance.name.strip()
cut_bool = False
cut_word = ["下线", "停用", "已经下线", "账号停用"]
for i in cut_word:
if name.find(i) >= 0:
cut_bool = True
item_dict = dict()
suggest_list = list()
if cut_bool == False:
item_dict = dict()
item_dict["id"] = getMd5Digest(str(name))
item_dict["ori_name"] = name
item_dict["is_online"] = instance.is_online
item_dict["order_weight"] = QueryWordAttr.get_hospital_query_word_weight(name)
item_dict["results_num"] = QueryWordAttr.get_query_results_num(name)
item_dict["type_flag"] = get_tips_word_type(name)
item_dict["offline_score"] = 0.0
item_dict["tips_name_type"] = 1
ret_list.append(item_dict)
suggest_list = get_tips_suggest_list_v1(name)
return (item_dict, suggest_list)
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return (dict(), list())
@classmethod
def get_hospital_lat_lng_info_to_redis(cls, instance):
try:
redis_key_prefix = "search_tips:hospital_latlng_info"
name = instance.name.strip()
lng = instance.baidu_loc_lng
lat = instance.baidu_loc_lat
pos_list = [lng, lat]
redis_client.hset(redis_key_prefix, name, pos_list)
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
......@@ -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
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
......@@ -103,3 +103,94 @@ class ItemWikiTransfer(object):
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return ([], [])
class ItemWikiTransferV1(object):
@classmethod
def get_wiki_data_name_mapping_results_to_redis(cls, instance):
try:
wiki_name = instance.name.strip()
if wiki_name:
multi_fields = {
'name': 1,
'association_tags': 1,
"description": 1,
"use_result": 1,
"treatment_method": 1,
"effect": 1,
"ingredient": 1,
"nature_type": 1,
"shape": 1,
}
query_fields = ['^'.join((k, str(v))) for (k, v) in multi_fields.items()]
multi_match = {
'query': wiki_name,
'type': 'cross_fields',
'operator': 'or',
'fields': query_fields,
}
q = {
"size": 0,
"query": {
"bool": {
"should": [
{"multi_match": multi_match}
],
"must": [
{"term": {"is_online": True}}
],
"minimum_should_match": 1
}
}
}
result_dict = ESPerform.get_search_results(ESPerform.get_cli(settings.GM_ORI_ES_INFO_LIST),
sub_index_name="newwiki", doc_type="newwiki", query_body=q,
offset=0, size=0)
doctor_results = result_dict["total_count"]
redis_key_prefix = "search_tips:tips_mapping_num"
redis_data = redis_client.hget(redis_key_prefix, wiki_name)
redis_val_dict = json.loads(str(redis_data, encoding="utf-8")) if redis_data else {}
total_count = doctor_results
if 't' in redis_val_dict:
total_count += int(redis_val_dict['t'])
redis_val_dict['t'] = total_count
redis_val_dict['w'] = doctor_results
redis_client.hset(redis_key_prefix, wiki_name, json.dumps(redis_val_dict))
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
@classmethod
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_v1(instance.name)
return (item_dict, suggest_list)
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return ([], [])
......@@ -9,7 +9,7 @@ from libs.es import ESPerform
from libs.cache import redis_client
import json
from trans2es.commons.commons import get_tips_suggest_list
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
......@@ -39,3 +39,31 @@ class ProduceWikiTransfer(object):
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return ([], [])
class ProduceWikiTransferV1(object):
@classmethod
def get_productwiki_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_v1(instance.name)
return (item_dict, suggest_list)
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return ([], [])
......@@ -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
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
......@@ -117,3 +117,108 @@ class TagTransfer(object):
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return ([], [])
class TagTransferV1(object):
tips_num_redis_key_prefix = "search_tips:tips_mapping_num"
@classmethod
def get_tag_data_name_mapping_results_to_redis(cls, instance):
try:
tag_name = instance.name.strip()
q = dict()
if tag_name:
multi_fields = {
'short_description': 1,
'doctor.name': 1,
'doctor.hospital.name': 1,
'doctor.hospital.city_name': 1,
'doctor.hospital.city_province_name': 1,
'closure_tags': 1, # 5.9版 搜索所有tag
'doctor.hospital.officer_name': 1 # 搜索机构管理者
}
query_fields = ['^'.join((k, str(v))) for (k, v) in multi_fields.items()]
multi_match = {
'query': tag_name,
'type': 'cross_fields',
'operator': 'and',
'fields': query_fields,
}
sku_query = {
"nested": {
"path": "sku_list",
"query": {
"multi_match": {
"query": tag_name,
"fields": ["sku_list.name^2"],
'operator': 'and',
'type': 'cross_fields'
}
}
}
}
q['query'] = {
'bool': {
"should": [
{'multi_match': multi_match},
sku_query
],
"must": [
{"term": {"is_online": True}}
],
"minimum_should_match": 1
}
}
result_dict = ESPerform.get_search_results(ESPerform.get_cli(settings.GM_ORI_ES_INFO_LIST),
sub_index_name="service", doc_type="service", query_body=q,
offset=0, size=0)
doctor_results = result_dict["total_count"]
redis_data = redis_client.hget(cls.tips_num_redis_key_prefix, tag_name)
redis_val_dict = json.loads(str(redis_data, encoding="utf-8")) if redis_data else {}
total_count = doctor_results
if 't' in redis_val_dict:
total_count += int(redis_val_dict['t'])
redis_val_dict['t'] = total_count
redis_val_dict['s'] = doctor_results
redis_client.hset(cls.tips_num_redis_key_prefix, tag_name, json.dumps(redis_val_dict))
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
@classmethod
def get_tag_suggest_data_list(cls, instance):
try:
ret_list = list()
keyword = instance.name
cut_bool = False
cut_word = ["下线", "停用", "已经下线", "账号停用"]
for i in cut_word:
if keyword.find(i) >= 0:
cut_bool = True
if cut_bool == False:
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"] = 0
ret_list.append(item_dict)
suggest_list = get_tips_suggest_list_v1(instance.name)
return (item_dict, suggest_list)
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return ([], [])
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