Commit 39739643 authored by lixiaofang's avatar lixiaofang

修改医生医院一级页面的接口

parent 5995ef9a
...@@ -24,5 +24,29 @@ ...@@ -24,5 +24,29 @@
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" /> <option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
</formatting-settings> </formatting-settings>
</DBN-SQL> </DBN-SQL>
<DBN-PSQL>
<case-options enabled="false">
<option name="KEYWORD_CASE" value="lower" />
<option name="FUNCTION_CASE" value="lower" />
<option name="PARAMETER_CASE" value="lower" />
<option name="DATATYPE_CASE" value="lower" />
<option name="OBJECT_CASE" value="preserve" />
</case-options>
<formatting-settings enabled="false" />
</DBN-PSQL>
<DBN-SQL>
<case-options enabled="false">
<option name="KEYWORD_CASE" value="lower" />
<option name="FUNCTION_CASE" value="lower" />
<option name="PARAMETER_CASE" value="lower" />
<option name="DATATYPE_CASE" value="lower" />
<option name="OBJECT_CASE" value="preserve" />
</case-options>
<formatting-settings enabled="false">
<option name="STATEMENT_SPACING" value="one_line" />
<option name="CLAUSE_CHOP_DOWN" value="chop_down_if_statement_long" />
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
</formatting-settings>
</DBN-SQL>
</code_scheme> </code_scheme>
</component> </component>
\ No newline at end of file
...@@ -155,9 +155,9 @@ class ESPerform(object): ...@@ -155,9 +155,9 @@ class ESPerform(object):
bulk_actions = [] bulk_actions = []
if sub_index_name=="topic" or \ if sub_index_name == "topic" or \
sub_index_name=="topic-star-routing" or \ sub_index_name == "topic-star-routing" or \
sub_index_name=="topic-high-star": sub_index_name == "topic-high-star":
for data in data_list: for data in data_list:
if data: if data:
bulk_actions.append({ bulk_actions.append({
...@@ -232,7 +232,7 @@ class ESPerform(object): ...@@ -232,7 +232,7 @@ class ESPerform(object):
return {"total_count": 0, "hits": []} return {"total_count": 0, "hits": []}
@classmethod @classmethod
def get_analyze_results(cls,es_cli, sub_index_name, query_body): def get_analyze_results(cls, es_cli, sub_index_name, query_body):
try: try:
assert (es_cli is not None) assert (es_cli is not None)
...@@ -242,7 +242,7 @@ class ESPerform(object): ...@@ -242,7 +242,7 @@ class ESPerform(object):
logging.error("index:%s is not existing,get_search_results error!" % official_index_name) logging.error("index:%s is not existing,get_search_results error!" % official_index_name)
return None return None
res = es_cli.indices.analyze(index=official_index_name,body=query_body) res = es_cli.indices.analyze(index=official_index_name, body=query_body)
return res return res
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
...@@ -298,8 +298,8 @@ class ESPerform(object): ...@@ -298,8 +298,8 @@ class ESPerform(object):
functions_list += [ functions_list += [
{ {
"filter": { "filter": {
"constant_score":{ "constant_score": {
"filter":{ "filter": {
"term": {"content_level": 6}} "term": {"content_level": 6}}
} }
}, },
...@@ -307,8 +307,8 @@ class ESPerform(object): ...@@ -307,8 +307,8 @@ class ESPerform(object):
}, },
{ {
"filter": { "filter": {
"constant_score":{ "constant_score": {
"filter":{ "filter": {
"term": {"content_level": 5}} "term": {"content_level": 5}}
} }
}, },
...@@ -316,8 +316,8 @@ class ESPerform(object): ...@@ -316,8 +316,8 @@ class ESPerform(object):
}, },
{ {
"filter": { "filter": {
"constant_score":{ "constant_score": {
"filter":{ "filter": {
"term": {"content_level": 4}} "term": {"content_level": 4}}
} }
}, },
...@@ -411,7 +411,7 @@ class ESPerform(object): ...@@ -411,7 +411,7 @@ class ESPerform(object):
} }
}, },
"_source": { "_source": {
"include": ["id","user_id"] "include": ["id", "user_id"]
}, },
"sort": [ "sort": [
{"_score": {"order": "desc"}}, {"_score": {"order": "desc"}},
...@@ -429,7 +429,8 @@ class ESPerform(object): ...@@ -429,7 +429,8 @@ class ESPerform(object):
"id": have_read_topic_id_list "id": have_read_topic_id_list
} }
} }
result_dict = ESPerform.get_search_results(ESPerform.get_cli(), sub_index_name="topic-high-star", query_body=q, result_dict = ESPerform.get_search_results(ESPerform.get_cli(), sub_index_name="topic-high-star",
query_body=q,
offset=0, size=size, routing="6") offset=0, size=size, routing="6")
topic_id_list = [item["_source"]["id"] for item in result_dict["hits"]] topic_id_list = [item["_source"]["id"] for item in result_dict["hits"]]
...@@ -441,7 +442,7 @@ class ESPerform(object): ...@@ -441,7 +442,7 @@ class ESPerform(object):
logging.info("topic_id_list:%s" % str(topic_id_dict)) logging.info("topic_id_list:%s" % str(topic_id_dict))
return topic_id_list,topic_id_dict return topic_id_list, topic_id_dict
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return list() return list()
...@@ -109,8 +109,6 @@ class GroupUtils(object): ...@@ -109,8 +109,6 @@ class GroupUtils(object):
"script": { "script": {
"lang": "expression", "lang": "expression",
"source": "_score+doc['offline_score']" "source": "_score+doc['offline_score']"
# "lang":"painless",
# "source":"_score+params._source.offline_score"
}, },
"order": "desc" "order": "desc"
} }
...@@ -214,3 +212,68 @@ class GroupUtils(object): ...@@ -214,3 +212,68 @@ class GroupUtils(object):
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return [] return []
@classmethod
def get_search_pictorial_topic(cls, query, offset, size):
try:
q = dict()
multi_fields = {
'name': 4,
'description': 4,
'tag_name': 4
}
query_fields = ['^'.join((k, str(v))) for (k, v) in multi_fields.items()]
multi_match = {
'query': query,
'type': 'cross_fields',
'operator': 'and',
'fields': query_fields,
}
q['query'] = {
'bool': {
"must": [
{"term": {"is_online": True}},
{"term": {"is_deleted": False}},
{"term": {"is_default": 0}},
{"range": {"topic_id_list": {"gte": 0}}},
{"term": {"is_cover": True}}
],
"should": [
{'multi_match': multi_match}
],
"minimum_should_match": 1
}
}
q["_source"] = {
"includes": ["id", "tag_name", "name", "description", "is_online", "is_cover", "topic_id_list",
"is_default"]
}
q["sort"] = [
{
"_script": {
"type": "number",
"script": {
"lang": "expression",
"source": "_score+doc['offline_score']"
},
"order": "desc"
}
},
{
"_score": {
"order": "desc"
}
}
]
logging.info("get qqqqqqqq:%s" % q)
es_cli_obj = ESPerform.get_cli()
result_dict = ESPerform.get_search_results(es_cli_obj, "pictorial", q, offset, size)
return result_dict
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return None
...@@ -261,3 +261,24 @@ def pictorial_topic_sort(pictorial_id=-1, offset=0, size=10): ...@@ -261,3 +261,24 @@ def pictorial_topic_sort(pictorial_id=-1, offset=0, size=10):
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return {"pict_pictorial_ids_list": []} return {"pict_pictorial_ids_list": []}
@bind("physical/search/pictorial_topic_sort")
def search_physical(query="", offset=0, size=10):
"""
搜索页面搜索画报
:param query:
:param offset:
:param size:
:return:
1. query识别:允许模糊匹配
2. 召回部分:去掉无封面、无帖子、下线的、默认画报
3. rank部分:(和之前一样,下面只是粘贴过来)
"""
try:
result_dicts = GroupUtils.get_search_pictorial_topic(query, offset, size)
logging.info("result_dicts:%s" % result_dicts)
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return {"search_topic_ids": []}
...@@ -16,7 +16,7 @@ import random ...@@ -16,7 +16,7 @@ import random
@bind("physical/search/search_hotword") @bind("physical/search/search_hotword")
def search_hotword(device_id=None, offset=0, size=10): def search_hotword(device_id=-1):
""" """
:remark:搜索页的热门灵感 :remark:搜索页的热门灵感
内容组成:搜索推荐热词register_show_tag 内容组成:搜索推荐热词register_show_tag
......
...@@ -137,14 +137,16 @@ def search_user(query="", offset=0, size=10): ...@@ -137,14 +137,16 @@ def search_user(query="", offset=0, size=10):
} }
result_dict = ESPerform.get_analyze_results( logging.info("get q:%s" % q)
ESPerform.get_cli(), sub_index_name="user", query_body=q, offset=offset, size=size es_cli_obj = ESPerform.get_cli()
) result_dict = ESPerform.get_search_results(es_cli_obj, "user", q, offset, size)
res = result_dict["hits"]["hits"] logging.info("get result_dict:%s" % result_dict)
user_id = [item["_source"]["user_id"] for item in res] res = result_dict["hits"]
if len(res) > 0:
user_id = [item["_source"]["user_id"] for item in res]
return {"search_user_id": user_id} return {"search_user_id": user_id}
except: except:
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
"topic_id_list":{"type":"long"}, "topic_id_list":{"type":"long"},
"effective":{"type":"boolean"}, "effective":{"type":"boolean"},
"offline_score":{"type":"long"}, "offline_score":{"type":"long"},
"is_default":{"type":"long"} "is_default":{"type":"long"},
"is_cover":{"type":"boolean"}
} }
} }
\ No newline at end of file
...@@ -63,27 +63,27 @@ class Pictorial(models.Model): ...@@ -63,27 +63,27 @@ class Pictorial(models.Model):
def get_topic_id(self): def get_topic_id(self):
try: try:
topic_id_list = list(PictorialTopics.objects.filter(pictorial_id=self.id,is_online=True,is_deleted=False).values_list("topic_id", flat=True)) topic_id_list = list(
PictorialTopics.objects.filter(pictorial_id=self.id, is_online=True, is_deleted=False).values_list(
"topic_id", flat=True))
return topic_id_list return topic_id_list
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return [] return []
def get_effective(self, topic_id_list):
def get_effective(self,topic_id_list):
try: try:
effective_num = 0 effective_num = 0
ret = False ret = False
for topic_id in topic_id_list: for topic_id in topic_id_list:
topic_id_object = Topic.objects.filter(id=int(topic_id)).first() topic_id_object = Topic.objects.filter(id=int(topic_id)).first()
if topic_id_object and topic_id_object.is_online and int(topic_id_object.content_level) in [0,3,4,5]: if topic_id_object and topic_id_object.is_online and int(topic_id_object.content_level) in [0, 3, 4, 5]:
effective_num += 1 effective_num += 1
if effective_num >= 5: if effective_num >= 5:
ret = True ret = True
break break
return ret return ret
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
...@@ -109,7 +109,8 @@ class Pictorial(models.Model): ...@@ -109,7 +109,8 @@ class Pictorial(models.Model):
def get_tag_by_id(self): def get_tag_by_id(self):
try: try:
tag_id_list = list(PictorialTag.objects.filter(pictorial_id=self.id, is_online=True).values_list("tag_id", flat=True)) tag_id_list = list(
PictorialTag.objects.filter(pictorial_id=self.id, is_online=True).values_list("tag_id", flat=True))
return tag_id_list return tag_id_list
except: except:
...@@ -125,6 +126,25 @@ class Pictorial(models.Model): ...@@ -125,6 +126,25 @@ class Pictorial(models.Model):
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return [] return []
def get_is_cover(self, topic_id_list):
try:
effective_num = 0
ret = False
for topic_id in topic_id_list:
topic_id_object = Topic.objects.filter(id=int(topic_id)).first()
if topic_id_object and topic_id_object.is_online and int(topic_id_object.content_level) in [3, 4, 5, 6]:
effective_num += 1
if effective_num >= 5:
ret = True
break
return ret
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return False
class PictorialTag(models.Model): class PictorialTag(models.Model):
"""画报关注标签""" """画报关注标签"""
......
...@@ -7,26 +7,27 @@ import traceback ...@@ -7,26 +7,27 @@ import traceback
from libs.tools import tzlc from libs.tools import tzlc
from trans2es.models.topic import Topic from trans2es.models.topic import Topic
class PictorialTransfer(object): class PictorialTransfer(object):
def __init__(self): def __init__(self):
pass pass
@classmethod @classmethod
def get_offline_score(cls,instance,topic_id_list): def get_offline_score(cls, instance, topic_id_list):
try: try:
total_offline_score = 0 total_offline_score = 0
topic_image_num = 0 topic_image_num = 0
for topic_id in topic_id_list: for topic_id in topic_id_list:
topic_image_num += Topic.get_topic_image_num(topic_id) topic_image_num += Topic.get_topic_image_num(topic_id)
if topic_image_num>=6 and topic_image_num<=10: if topic_image_num >= 6 and topic_image_num <= 10:
total_offline_score += 30 total_offline_score += 30
elif topic_image_num>10 and topic_image_num<=20: elif topic_image_num > 10 and topic_image_num <= 20:
total_offline_score += 60 total_offline_score += 60
elif topic_image_num>20 and topic_image_num<=50: elif topic_image_num > 20 and topic_image_num <= 50:
total_offline_score += 80 total_offline_score += 80
elif topic_image_num>50: elif topic_image_num > 50:
total_offline_score += 100 total_offline_score += 100
total_offline_score += instance.add_score total_offline_score += instance.add_score
...@@ -62,10 +63,11 @@ class PictorialTransfer(object): ...@@ -62,10 +63,11 @@ class PictorialTransfer(object):
tag_id_list = instance.get_tag_by_id() tag_id_list = instance.get_tag_by_id()
res["tag_id"] = tag_id_list res["tag_id"] = tag_id_list
res["tag_name"] = instance.get_tag_by_name(tag_id_list) res["tag_name"] = instance.get_tag_by_name(tag_id_list)
res["topic_id_list"] =instance.get_topic_id() res["topic_id_list"] = instance.get_topic_id()
res["effective"] = instance.get_effective(res["topic_id_list"]) res["effective"] = instance.get_effective(res["topic_id_list"])
res["offline_score"] = cls.get_offline_score(instance,res["topic_id_list"]) res["offline_score"] = cls.get_offline_score(instance, res["topic_id_list"])
res["is_default"] = instance.is_default res["is_default"] = instance.is_default
res["is_cover"] = instance.get_is_cover(res["topic_id_list"])
return res return res
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) 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