Commit 30688c82 authored by 段英荣's avatar 段英荣

modify

parent 42e439b6
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gm_rpcd.all import bind
import logging
import traceback
@bind("physical/search/home_recommend")
def home_recommend(user_id=-1):
"""
:remark:首页推荐,目前只推荐日记
:return:
"""
try:
# 获取user_id 关注的用户集合
attention_user_id_list = list()
# 获取user_id pick的用户集合
pick_user_id_list = list()
# 参与的小组发帖
# 马甲账号集合
vest_account_list = list()
q = dict()
q["filter"] = {
"range":{"content_level":{"gte":3,"lte":5}}
}
query_function_score = dict()
functions = [
{
"filter":{"match":{"user_id":attention_user_id_list}},
"weight": 5,
},
{
"filter":{"match":{"user_id":pick_user_id_list}},
"weight":3
},
{
"filter": {"match": {"user_id": vest_account_list}},
"weight": 0.5
},
{
"filter":{"match":{"content_level":5}},
"weight":5
},
{
"filter":{"match":{"content_level":4}},
"weight":3
},
{
"filter":{"match":{"content_level":3}},
"weight":2
}
]
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
......@@ -50,7 +50,7 @@ class Command(BaseCommand):
from optparse import make_option
option_list = BaseCommand.option_list + (
make_option('-t', '--type', dest='type_list', action='append', help='type name to dump data to elasticsearch', metavar='TYPE'),
make_option('-t', '--type', dest='type_list', action='append', help='type name to dump data to elasticsearch', metavar='TYPE',default=''),
make_option('-i', '--index-prefix', dest='index_prefix', help='index name to dump data to elasticsearch', metavar='INDEX_PREFIX'),
make_option('-p', '--parallel', dest='parallel', help='parallel process count', metavar='PARALLEL'),
make_option('-s', '--pks', dest='pks', help='specify sync pks, comma separated', metavar='PKS', default=''),
......@@ -60,9 +60,17 @@ class Command(BaseCommand):
def handle(self, *args, **options):
try:
option_type_list = list()
if len(self.option_list.type_list) > 0:
option_type_list = self.option_list.type_list.split(",")
type_name_list = get_type_info_map().keys()
for type_name in type_name_list:
if type_name not in option_type_list:
logging.warning("type_name:%s can not need to execute!" % type_name)
continue
type_info = get_type_info_map()[type_name]
query_set = type_info.queryset
......
......@@ -3,6 +3,10 @@
"properties": {
"id":{"type":"long"},
"name":{"type":"text"},
"icon":{"type":"text"}
"icon":{"type":"text"},
"tag_list":{"type":"string"},
"attention_user_id_list":{"type":"string"},
"pick_user_id_list":{"type":"string"},
"same_group_user_id_list":{"type":"string"}
}
}
\ No newline at end of file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
import traceback
import logging
from libs.es import ESPerform
from django.db import models
import datetime
from .user import User
class PickUserRecord(models.Model):
class Meta:
verbose_name = u'pickuserrecord'
verbose_name_plural = u'pickuserrecord'
db_table = 'pickuserrecord'
app_label = 'api'
pickuser_id = models.IntegerField(verbose_name="pick user id")
#user_id = models.IntegerField(verbose_name="用户ID")
is_deleted = models.BooleanField(verbose_name="是否删除")
is_pick = models.BooleanField(verbose_name="is_pick")
create_time = models.DateTimeField(verbose_name=u'日记创建时间',default=datetime.datetime.fromtimestamp(0))
update_time = models.DateTimeField(verbose_name=u'日记更新时间', default=datetime.datetime.fromtimestamp(0))
user = models.ForeignKey(User,related_name="user_pick",verbose_name="pick用户信息")
......@@ -16,10 +16,11 @@ class Topic(models.Model):
db_table = 'topic'
app_label = 'api'
group_id = models.IntegerField(verbose_name='日记ID')
id = models.IntegerField(verbose_name='日记ID')
create_time = models.DateTimeField(verbose_name=u'日记创建时间',default=datetime.datetime.fromtimestamp(0))
update_time = models.DateTimeField(verbose_name=u'日记更新时间', default=datetime.datetime.fromtimestamp(0))
name = models.CharField(verbose_name='日记名称')
group_id = models.IntegerField(verbose_name='用户所在组ID')
user_id = models.IntegerField(verbose_name='用户ID')
description = models.CharField(verbose_name='日记本描述')
content = models.CharField(verbose_name='日记本内容')
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
import traceback
import logging
from libs.es import ESPerform
from django.db import models
import datetime
class User(models.Model):
class Meta:
verbose_name = u'用户'
verbose_name_plural = u'用户'
db_table = 'user'
app_label = 'api'
id = models.IntegerField(verbose_name="用户ID")
name = models.CharField(verbose_name="用户名称")
icon = models.CharField(verbose_name='')
def get_follow_user_id_list(self):
follow_user_id_list = list()
user_follows = self.user_follow.filter(is_online=True)
for user_follow in user_follows:
follow_user_id_list.append(user_follow.follow_id)
return follow_user_id_list
def get_pick_user_id_list(self):
pick_user_id_list = list()
user_picks = self.user_pick.filter(is_deleted=False)
for user_pick in user_picks:
pick_user_id_list.append(user_pick.pickuser_id)
return pick_user_id_list
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
import traceback
import logging
from libs.es import ESPerform
from django.db import models
import datetime
from .user import User
class UserFollow(models.Model):
class Meta:
verbose_name = u'用户关注'
verbose_name_plural = u'用户关注'
db_table = 'user_follow'
app_label = 'api'
#user_id = models.IntegerField(verbose_name="用户ID")
user = models.ForeignKey(User,related_name="user_follow",verbose_name="关注用户信息")
follow_id = models.IntegerField(verbose_name="关注的用户ID")
is_online = models.BooleanField(verbose_name="是否上线")
is_deleted = models.BooleanField(verbose_name="是否删除")
create_time = models.DateTimeField(verbose_name=u'日记创建时间',default=datetime.datetime.fromtimestamp(0))
update_time = models.DateTimeField(verbose_name=u'日记更新时间', default=datetime.datetime.fromtimestamp(0))
......@@ -12,8 +12,9 @@ import elasticsearch
import elasticsearch.helpers
import sys
from trans2es.models import topic
from trans2es.models import topic,user
from trans2es.utils.topic_transfer import TopicTransfer
from trans2es.utils.user_transfer import UserTransfer
from libs.es import ESPerform
......@@ -242,6 +243,16 @@ def get_type_info_map():
bulk_insert_chunk_size=100,
round_insert_chunk_size=5,
round_insert_period=2,
),
TypeInfo(
name = "user", #用户
type="user",
model=user.User,
query_deferred=lambda:user.User.objects.all().query,
get_data_func=UserTransfer.get_user_data,
bulk_insert_chunk_size=100,
round_insert_chunk_size=5,
round_insert_period=2,
)
]
......
......@@ -16,6 +16,10 @@ class UserTransfer(object):
res["id"] = instance.id
res["icon"] = instance.icon
res["name"] = instance.name
res["tag_list"] = ""
res["attention_user_id_list"] = instance.get_follow_user_id_list
res["pick_user_id_list"] = instance.pick_user_id_list
res["same_group_user_id_list"] = ""
return res
except:
......
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