Commit a583592c authored by lixiaofang's avatar lixiaofang

Merge branch 'test' of git.wanmeizhensuo.com:alpha/physical into test

parents 0549e555 04a8bba6
......@@ -18,13 +18,14 @@ class ESPerform(object):
index_prefix = settings.ES_INDEX_PREFIX
@classmethod
def get_cli(cls):
def get_cli(cls, cli_info=None):
try:
init_args = {
'sniff_on_start': False,
'sniff_on_connection_fail': False,
}
cls.cli_obj = Elasticsearch(hosts=cls.cli_info_list, **init_args)
es_cli_info = cli_info if cli_info else cls.cli_info_list
cls.cli_obj = Elasticsearch(hosts=es_cli_info, **init_args)
return cls.cli_obj
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
......@@ -230,6 +231,23 @@ class ESPerform(object):
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return {"total_count": 0, "hits": []}
@classmethod
def get_analyze_results(cls,es_cli, sub_index_name, query_body):
try:
assert (es_cli is not None)
official_index_name = cls.get_official_index_name(sub_index_name, "read")
index_exists = es_cli.indices.exists(official_index_name)
if not index_exists:
logging.error("index:%s is not existing,get_search_results error!" % official_index_name)
return None
res = es_cli.indices.analyze(index=official_index_name,body=query_body)
return res
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return None
@classmethod
def if_es_node_load_high(cls, es_cli):
try:
......
......@@ -181,7 +181,7 @@ class TopicUtils(object):
"content_level": 6
}
},
"weight": 200
"weight": 1000
}
]
......
......@@ -12,6 +12,7 @@ from libs.cache import redis_client
from search.utils.common import *
from trans2es.models.tag import TopicTag,AccountUserTag,CommunityTagFollow,Tag
import time
from django.conf import settings
def get_highlight(fields=[]):
......@@ -150,3 +151,28 @@ def choice_push_tag(device_id, user_id):
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return {"tag_list": []}
@bind("physical/search/identity_tag_name")
def identity_tag_name(topic_content):
try:
ret_tag_list = list()
redis_key_name = "physical:tag_name_set"
body = {
'text': topic_content,
'analyzer': "gm_default_search"
}
cli_info = settings.TAG_ES_INFO_LIST
res = ESPerform.get_analyze_results(es_cli=ESPerform.get_cli(cli_info=cli_info), sub_index_name="tag", query_body=body)
for item in res["tokens"]:
token_word = item["token"]
is_member = redis_client.sismember(redis_key_name, token_word)
if is_member:
ret_tag_list.append(token_word)
return {"tag_name_list": ret_tag_list}
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return {"tag_name_list": []}
{
"dynamic":"strict",
"properties": {
"name":{"type":"keyword"}
}
}
\ No newline at end of file
......@@ -466,6 +466,16 @@ def get_type_info_map():
round_insert_chunk_size=5,
round_insert_period=2,
),
TypeInfo(
name="tag-name", # 标签名字
type="tag-name",
model=tag.Tag,
query_deferred=lambda: tag.Tag.objects.all().query,
get_data_func=TagTransfer.get_tag_name_data,
bulk_insert_chunk_size=100,
round_insert_chunk_size=5,
round_insert_period=2,
),
TypeInfo(
name='contrast_similar', # facesimilar
type='contrast_similar',
......
......@@ -16,6 +16,17 @@ from django.conf import settings
class TagTransfer(object):
@classmethod
def get_tag_name_data(cls,instance):
try:
res = dict()
res["name"] = instance.name
return res
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return dict()
@classmethod
def get_tag_data(cls,instance):
try:
......
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