Commit 96e96568 authored by Kai's avatar Kai

Merge branch 'hk' into hk_now

parents 7cf6330b b9d20bc7
......@@ -24,29 +24,5 @@
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
</formatting-settings>
</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>
</component>
\ No newline at end of file
......@@ -35,7 +35,7 @@ class TopicUtils(object):
}
q["_source"] = {
"include": ["tag_list", "attention_user_id_list", "pick_user_id_list", "same_pictorial_user_id_list"]
"include": ["tag_list","useful_tag_list","attention_user_id_list", "pick_user_id_list", "same_pictorial_user_id_list"]
}
result_dict = ESPerform.get_search_results(ESPerform.get_cli(), "user", q, offset, size)
......@@ -127,7 +127,7 @@ class TopicUtils(object):
query_type=TopicPageType.HOME_RECOMMEND,
filter_topic_id_list=[], test_score=False, must_topic_id_list=[], recommend_tag_list=[],
user_similar_score_list=[], index_type="topic", routing=None, attention_tag_list=[],
linucb_user_id_list=[], disable_collpase=False):
linucb_user_id_list=[], disable_collpase=False,usefulrecall = -1):
"""
:remark:获取首页推荐帖子列表
:param user_id:
......@@ -141,14 +141,14 @@ class TopicUtils(object):
# pick_user_id_list = list()
# same_group_id_list = list()
user_tag_list = list()
useful_tag_id_list = list()
result_dict = TopicUtils.get_related_user_info(user_id, 0, 1)
if len(result_dict["hits"]) == 0:
logging.warning("not find user_id:%d in es!" % int(user_id))
else:
attention_user_info_list = result_dict["hits"][0]["_source"]["attention_user_id_list"]
attention_user_id_list = [item["user_id"] for item in attention_user_info_list]
useful_tag_id_list = result_dict["hits"][0]["_source"]["useful_tag_list"]
# pick_user_info_list = result_dict["hits"][0]["_source"]["pick_user_id_list"]
# pick_user_id_list = [item["user_id"] for item in pick_user_info_list]
......@@ -197,7 +197,14 @@ class TopicUtils(object):
"weight": 100
}
)
if len(useful_tag_id_list) > 0 and usefulrecall!= -1:
functions_list.append(
{
"filter": {"bool": {
"must": {"terms": {"tag_list": useful_tag_id_list}}}},
"weight": 100
}
)
query_function_score = {
"query": {
"bool": {
......
......@@ -10,6 +10,7 @@ from libs.es import ESPerform
from search.utils.group import GroupUtils
from search.utils.common import GroupSortTypes
from libs.es import ESPerform
from trans2es.models.pictorial import PictorialTopics
@bind("physical/search/query_pictorial")
......@@ -209,7 +210,7 @@ def pictorial_topic(topic_id=-1, offset=0, size=10):
@bind("physical/search/pictorial_topic_sort")
def pictorial_topic_sort(pictorial_id=-1, offset=0, size=10):
"""
:remark 小组排序,缺少:前1天发评论人数*x
:remark 画报排序 人气 部分
:param user_id:
:param sort_type:
:param offset:
......@@ -241,12 +242,15 @@ def pictorial_topic_sort(pictorial_id=-1, offset=0, size=10):
es_cli_obj = ESPerform.get_cli()
result_dict = ESPerform.get_search_results(es_cli_obj, "topic", q, offset, size)
logging.info("get pictorial_topic_sort res:%s"%result_dict)
for item in result_dict["hits"]:
topic_id = item["_source"]["id"]
pict_pictorial_ids_list.append(topic_id)
if len(pict_pictorial_ids_list)>0 and offset==0:
pict_pictorial_ids_list = list(
PictorialTopics.objects.filter(pictorial_id=pictorial_id, is_online=True, is_deleted=False).values_list(
"topic_id", flat=True)[offset:size])
return {"pict_pictorial_ids_list":pict_pictorial_ids_list}
except:
......
......@@ -17,6 +17,7 @@
"user_nick_name_pre": {"type":"text","analyzer":"keyword"}, //不切词的用户名
"group_id":{"type":"long"}, //所在组ID
"tag_list":{"type":"long"},//标签属性
"useful_tag_list":{"type":"long"},//有用标签属性
"edit_tag_list":{"type":"long"},//编辑标签
"tag_name_list":{"type":"text","analyzer":"gm_default_index","search_analyzer":"gm_default_index"},
"share_num":{"type":"long"},
......
......@@ -16,6 +16,7 @@
"user_nick_name":{"type":"text","analyzer":"gm_default_index","search_analyzer":"gm_default_index"},//帖子用户名
"user_nick_name_pre": {"type":"text","analyzer":"keyword"}, //不切词的用户名
"group_id":{"type":"long"}, //所在组ID
"useful_tag_list":{"type":"long"},//有用标签属性
"tag_list":{"type":"long"},//标签属性
"edit_tag_list":{"type":"long"},//编辑标签
"tag_name_list":{"type":"text","analyzer":"gm_default_index","search_analyzer":"gm_default_index"},
......
......@@ -17,6 +17,7 @@
"user_nick_name_pre": {"type":"text","analyzer":"keyword"}, //不切词的用户名
"group_id":{"type":"long"}, //所在组ID
"tag_list":{"type":"long"},//标签属性
"useful_tag_list":{"type":"long"},//有用标签属性
"edit_tag_list":{"type":"long"},//编辑标签
"tag_name_list":{"type":"text","analyzer":"gm_default_index","search_analyzer":"gm_default_index"},
"share_num":{"type":"long"},
......
......@@ -9,6 +9,7 @@
"is_online":{"type":"boolean"},//是否上线
"is_deleted":{"type":"boolean"},
"tag_list":{"type":"long"},//标签属性
"useful_tag_list":{"type":"long"},//有用标签属性
"city_id":{"type":"text"},
"country_id":{"type":"text"},
"is_recommend":{"type":"boolean"},//是否运营推荐用户
......
......@@ -20,6 +20,7 @@ class TopicTag(models.Model):
topic_id = models.IntegerField(verbose_name=u"帖子ID")
is_online = models.BooleanField(verbose_name=u"是否在线")
is_collection = models.IntegerField(verbose_name=u"是否编辑标签")
is_body_esthetics = models.IntegerField(verbose_name=u"是否有用标签")
class AccountUserTag(models.Model):
......@@ -33,6 +34,7 @@ class AccountUserTag(models.Model):
is_deleted = models.BooleanField(verbose_name=u"是否删除")
create_time = models.DateTimeField(verbose_name=u'创建时间',default=datetime.datetime.fromtimestamp(0))
update_time = models.DateTimeField(verbose_name=u'更新时间', default=datetime.datetime.fromtimestamp(0))
is_body_esthetics = models.IntegerField(verbose_name=u"是否有用标签")
class Tag(models.Model):
......
......@@ -191,6 +191,22 @@ class Topic(models.Model):
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return ([],[])
def get_topic_useful_tag_id_list(self):
try:
topic_useful_tag_id_list = list()
tag_id_list = TopicTag.objects.using(settings.SLAVE_DB_NAME).filter(topic_id=self.id).values_list("tag_id","is_online","is_body_esthetics",flat=True)
for tag_item in tag_id_list:
is_online=tag_item.is_online
is_body_esthetics=tag_item.is_body_esthetics
if is_online and is_body_esthetics != 0:
topic_useful_tag_id_list.append(tag_item.tag_id)
return topic_useful_tag_id_list
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
def get_tag_name_list(self, tag_id_list):
try:
tag_name_list = list()
......
......@@ -189,3 +189,16 @@ class User(models.Model):
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
def get_user_useful_tag_id_list(self):
try:
user_useful_tag_id_list = list()
query_results = AccountUserTag.objects.using(settings.SLAVE_DB_NAME).filter(user=self.user_id,is_body_esthetics =1, is_deleted=False)
for item in query_results:
user_useful_tag_id_list.append(item.tag_id)
return user_useful_tag_id_list
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
\ No newline at end of file
......@@ -75,6 +75,11 @@ class TopicTransfer(object):
end = time.time()
time4 = (end-begin)
# begin = time.time()
topic_useful_tag_id_list= instance.get_topic_useful_tag_id_list()
res["useful_tag_list"] = topic_useful_tag_id_list
# end = time.time()
# time5 = (end - begin)
# # 片假名
# re_jp_pian_words = re.compile(u"[\u30a0-\u30ff]+")
# m_pian = re_jp_pian_words.search(instance.content, 0)
......
......@@ -73,6 +73,7 @@ class UserTransfer(object):
try:
res["tag_list"] = instance.get_user_tag_id_list()
res["useful_tag_list"] = instance.get_user_useful_tag_id_list()
res["attention_user_id_list"] = cls.get_follow_user_id_list(userInstance=instance)
# res["attention_group_id_list"] = instance.get_attention_group_id_list()
......
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