Commit 3cfbd8f3 authored by lixiaofang's avatar lixiaofang

add

parent 59730e1f
......@@ -208,27 +208,3 @@ class ESPerform(object):
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return {"total_count": 0, "hits": []}
@classmethod
def es_indices_analyze(cls, doc_type, body, es):
if es is None:
es = ESPerform.get_cli(settings.GM_ORI_ES_INFO_LIST)
index = ESPerform.es_index_adapt(
index_prefix=settings.ES_INDEX_PREFIX,
doc_type=doc_type,
rw='read'
)
res = es.indices.analyze(index=index, body=body)
return res
@classmethod
def es_index_adapt(cls, index_prefix, doc_type, rw=None):
"""get the adapted index name
"""
assert rw in [None, 'read', 'write']
index = '-'.join((index_prefix, doc_type))
if rw:
index = '-'.join((index, rw))
return index
......@@ -109,13 +109,11 @@ def get_suggest_tips(query, lat, lng, offset=0, size=50):
"offline_score": 0,
"type_flag": get_tips_word_type(ori_name), "highlight_name": ori_name, "describe": ""})
return ret_list
if len(ret_list >= 50):
return ret_list[0:50]
else:
return ret_list
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
......
......@@ -198,9 +198,9 @@ def get_tips_word_type(query=''):
key = QUERY_KEY.format(query_base64)
labels = list(map(lambda x: x.decode("utf8"), list(redis_client.smembers(key))))
labels.append(MIND_TYPE.UNKNOWN)
if query in QUERY_WORD_LABEL_NEED_MODIFIED:
labels.append(MIND_TYPE.PROJECT)
logging.info("get labels:%s" % labels)
labels.sort(key=label_key, reverse=True)
return labels[0]
......@@ -463,6 +463,16 @@ def tips_attr_sync_to_redis_type_info_map():
bulk_insert_chunk_size=100,
round_insert_chunk_size=5,
round_insert_period=2,
),
TypeInfo(
name='suggest',
type='wordresemble_results_num', # api_wordrelresemble
model=doctor.Hospital,
query_deferred=lambda: wordresemble.WordRel.objects.all().query,
get_data_func=WordResemble.set_data_to_redis,
bulk_insert_chunk_size=100,
round_insert_chunk_size=5,
round_insert_period=2,
)
]
......
......@@ -68,17 +68,14 @@ class ItemWikiTransfer(object):
redis_val_dict = json.loads(str(redis_data, encoding="utf-8")) if redis_data else {}
total_count = doctor_results
if 'w' in redis_val_dict:
total_count += int(redis_val_dict['w'])
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))
logging.info("get ----------------------get ")
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
......
......@@ -77,8 +77,8 @@ class TagTransfer(object):
redis_val_dict = json.loads(str(redis_data, encoding="utf-8")) if redis_data else {}
total_count = doctor_results
if 's' in redis_val_dict:
total_count += int(redis_val_dict['s'])
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
......
......@@ -143,7 +143,7 @@ class WordResemble(object):
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
@classmethod
def set_data_to_redis(cls):
def set_data_to_redis(cls, instance):
try:
QUERY_KEY = "query:{}:search_tips"
......@@ -156,8 +156,6 @@ class WordResemble(object):
words = list(sql_obj.all_resembles.all().values_list('word', flat=True))
for items in words:
# 先存储本体词
logging.info("get wordrm:%s" % wordrm["keyword"])
logging.info("get words:%s" % words)
query_base64 = base64.b64encode(wordrm["keyword"].encode('utf8')).decode('utf8')
key = QUERY_KEY.format(query_base64)
value_name = base64.b64encode(items.encode('utf8')).decode('utf8')
......@@ -171,8 +169,6 @@ class WordResemble(object):
# 存储到Redis
value = value_name + str(":" + str(total_count))
redis_client.sadd(key, value)
logging.info("get value:%s" % value)
# 存储近义词
query_base64 = base64.b64encode(items.encode('utf8')).decode('utf8')
key = QUERY_KEY.format(query_base64)
......@@ -186,10 +182,8 @@ class WordResemble(object):
# 存储结果
value = value_name + str(":" + str(total_count))
redis_client.sadd(key, value)
logging.info("get value:%s" % value)
if words:
for w in words:
logging.info("get word_pops:%s" % words)
value_name = base64.b64encode(w.encode('utf8')).decode('utf8')
redis_data = redis_client.hget(tips_num_redis_key_prefix, w)
redis_val_dict = json.loads(str(redis_data, encoding="utf-8")) if redis_data else {}
......@@ -198,8 +192,6 @@ class WordResemble(object):
total_count = int(redis_val_dict['t'])
value = value_name + str(":" + str(total_count))
redis_client.sadd(key, value)
logging.info("get value:%s" % value)
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