Commit 8a991816 authored by 段英荣's avatar 段英荣

modify

parent 6e1cf878
......@@ -148,3 +148,30 @@ class ESPerform(object):
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return False
@classmethod
def get_search_results(cls, es_cli,sub_index_name,query_body,offset=0,size=10,
auto_create_index=False,doc_type="_doc"):
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:
if not auto_create_index:
logging.error("index:%s is not existing,get_search_results error!" % official_index_name)
return None
else:
cls.create_index(es_cli,sub_index_name)
cls.put_index_mapping(es_cli,sub_index_name)
res = es_cli.search(index=official_index_name,doc_type=doc_type,body=query_body,from_=offset,size=size)
result_dict = {
"total_count":res["hits"]["total"],
"hits":res["hits"]["hits"]
}
return result_dict
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return None
\ No newline at end of file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import traceback
from libs.es import ESPerform
class TopicUtils(object):
@classmethod
def get_related_user_info(cls, user_id, offset=0, size=10):
"""
:remark:获取指定用户相关用户列表
:param user_id:
:param offset:
:param size:
:return:
"""
try:
q = dict()
q["query"] = {
"user_id": user_id
}
q["_souce"] = ["attention_user_id_list", "pick_user_id_list", "same_group_user_id_list"]
result_dict = ESPerform.get_search_results(ESPerform.get_cli(), "topic", q, offset, size)
return result_dict
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return None
......@@ -4,12 +4,11 @@
from gm_rpcd.all import bind
import logging
import traceback
from search.utils.topic import TopicUtils
@bind("physical/search/home_recommend")
def home_recommend(user_id=-1):
def home_recommend(user_id=-1,offset=0,size=10):
"""
:remark:首页推荐,目前只推荐日记
:return:
......@@ -23,6 +22,9 @@ def home_recommend(user_id=-1):
# 马甲账号集合
vest_account_list = list()
result_dict = TopicUtils.get_related_user_info(user_id,offset,size)
q = dict()
q["filter"] = {
"range":{"content_level":{"gte":3,"lte":5}}
......
......@@ -10,9 +10,27 @@
"tag_list":{"type":"text"},//标签属性
"city_id":{"type":"long"},
"country_id":{"type":"long"},
"attention_user_id_list":{"type":"long"},//关注用户列表
"pick_user_id_list":{"type":"long"},//pick用户列表
"same_group_user_id_list":{"type":"text"},//同组用户列表
"attention_user_id_list":{//关注用户列表
"type":"nested",
"properties":{
"user_id":{"type":"long"},
"country_id":{"type":"long"}
}
},
"pick_user_id_list":{//pick用户列表
"type":"nested",
"properties":{
"user_id":{"type":"long"},
"country_id":{"type":"long"}
}
},
"same_group_user_id_list":{//同组用户列表
"type":"nested",
"properties":{
"user_id":{"type":"long"},
"country_id":{"type":"long"}
}
},
"create_time":{"type":"date", "format":"date_time_no_millis"},
"update_time":{"type":"date", "format":"date_time_no_millis"}
}
......
......@@ -36,7 +36,16 @@ class User(models.Model):
for user_follow in user_follows:
follow_user_id_list.append(user_follow.follow_id)
return follow_user_id_list
follow_user_detail_list = list()
sql_data_list = self.objects.get(id__in=follow_user_id_list)
for detail_data in sql_data_list:
item = {
"usr_id":detail_data.user_id,
"country_id":detail_data.country_id
}
follow_user_detail_list.append(item)
return follow_user_detail_list
def get_pick_user_id_list(self):
pick_user_id_list = list()
......@@ -44,7 +53,16 @@ class User(models.Model):
for user_pick in user_picks:
pick_user_id_list.append(user_pick.pickuser_id)
return pick_user_id_list
pick_user_detail_list = list()
sql_data_list = self.objects.get(id__in=pick_user_id_list)
for detail_data in sql_data_list:
item = {
"usr_id":detail_data.user_id,
"country_id":detail_data.country_id
}
pick_user_detail_list.append(item)
return pick_user_detail_list
def get_same_group_user_id_list(self):
same_group_user_id_list = list()
......@@ -55,6 +73,15 @@ class User(models.Model):
for user_items_list in user_items_list:
same_group_user_id_list.append(user_items_list.user_id)
return same_group_user_id_list
same_group_detail_list = list()
sql_data_list = self.objects.get(id__in=same_group_user_id_list)
for detail_data in sql_data_list:
item = {
"usr_id":detail_data.user_id,
"country_id":detail_data.country_id
}
same_group_detail_list.append(item)
return same_group_detail_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