Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
physical
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alpha
physical
Commits
3fec999d
Commit
3fec999d
authored
Aug 23, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Plain Diff
add
parents
595cecb8
a7cee0ca
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
110 additions
and
36 deletions
+110
-36
collect_data.py
linucb/views/collect_data.py
+10
-6
user.py
search/utils/user.py
+2
-2
group.py
search/views/group.py
+57
-18
topic.py
search/views/topic.py
+40
-9
tag.py
trans2es/models/tag.py
+1
-0
topic.py
trans2es/models/topic.py
+0
-1
No files found.
linucb/views/collect_data.py
View file @
3fec999d
...
...
@@ -189,11 +189,11 @@ class CollectData(object):
click_results
=
TopicTag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
topic_id
=
topic_id
,
is_online
=
True
)
.
values_list
(
"tag_id"
,
"is_collection"
)
for
tag_id
,
is_collection
in
click_results
:
topic_tag_list
.
append
(
tag_id
)
#
topic_tag_list.append(tag_id)
if
is_collection
:
click_
topic_tag_list
.
append
(
tag_id
)
topic_tag_list
.
append
(
tag_id
)
tag_query_results
=
Tag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
id__in
=
topic_tag_list
,
is_online
=
True
,
is_deleted
=
False
)
.
values_list
(
"id"
,
id__in
=
topic_tag_list
,
is_online
=
True
,
is_deleted
=
False
,
is_category
=
False
)
.
values_list
(
"id"
,
"is_ai"
)
for
id
,
is_ai
in
tag_query_results
:
if
is_ai
:
...
...
@@ -207,7 +207,7 @@ class CollectData(object):
device_id
=
raw_val_dict
[
"device"
][
"device_id"
]
user_id
=
raw_val_dict
[
"user_id"
]
if
"user_id"
in
raw_val_dict
else
None
if
query_type
==
"do"
:
tag_list
=
list
(
Tag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
name
=
tag_name
,
is_online
=
True
,
is_deleted
=
False
)
.
values_list
(
"id"
,
flat
=
True
))
tag_list
=
list
(
Tag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
name
=
tag_name
,
is_online
=
True
,
is_deleted
=
False
,
is_category
=
False
)
.
values_list
(
"id"
,
flat
=
True
))
click_topic_tag_list
.
extend
(
tag_list
)
logging
.
info
(
"query tag attention,positive tag_list,device_id:
%
s,query_name:
%
s,tag_list:
%
s"
%
(
str
(
device_id
),
tag_name
,
str
(
click_topic_tag_list
)))
...
...
@@ -292,15 +292,19 @@ class CollectData(object):
# if len(exposure_sql_query_results)>0:
if
len
(
tagid_list
)
>
0
:
tag_query_results
=
Tag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
id__in
=
tagid_list
,
is_online
=
True
,
is_deleted
=
False
,
is_category
=
False
)
.
values_list
(
"id"
,
flat
=
True
)
is_click
=
1
is_vote
=
0
reward
=
1
if
is_click
or
is_vote
else
0
for
tag_id
in
tag
id_list
:
for
tag_id
in
tag
_query_results
:
self
.
update_user_linucb_tag_info
(
reward
,
device_id
,
tag_id
,
user_feature
)
# 更新该用户的推荐tag数据,放在 更新完成user tag行为信息之后
self
.
update_recommend_tag_list
(
device_id
,
user_feature
,
user_id
,
new_user_click_tag_list
=
tagid_list
)
self
.
update_recommend_tag_list
(
device_id
,
user_feature
,
user_id
,
new_user_click_tag_list
=
tag_query_results
)
else
:
logging
.
warning
(
"unknown type msg:
%
s"
%
raw_val_dict
.
get
(
"type"
,
"missing type"
))
except
:
...
...
search/utils/user.py
View file @
3fec999d
...
...
@@ -275,9 +275,10 @@ class UserUtils(object):
for
query_item
in
batch_query_list
:
query_body
+=
"{}
\n
{}
\n
"
.
format
(
json
.
dumps
(
search_header_dict
),
json
.
dumps
(
query_item
))
ret_dict
=
dict
()
if
len
(
query_body
)
>
0
:
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
sub_index_name
=
"user"
,
query_body
=
query_body
,
batch_search
=
True
)
ret_dict
=
dict
()
user_index
=
0
for
res_item
in
result_dict
[
"responses"
]:
recommend_user_list
=
list
()
...
...
@@ -289,7 +290,6 @@ class UserUtils(object):
user_index
+=
1
logging
.
info
(
"duan add,ret_dict:
%
s"
%
str
(
ret_dict
))
return
ret_dict
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
...
search/views/group.py
View file @
3fec999d
...
...
@@ -13,6 +13,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.topic
import
CommunityCategoryTagRelation
from
trans2es.models.pictorial
import
PictorialTopics
from
trans2es.models.pictorial
import
CommunityPictorialActivity
from
alpha_types.venus
import
PICTORIAL_ACTIVITY_SORT
...
...
@@ -96,6 +97,10 @@ def pictorial_sort(user_id=-1, sort_type=GroupSortTypes.HOT_RECOMMEND, offset=0,
@bind
(
"physical/search/pictorial_topic"
)
def
pictorial_topic
(
topic_id
=-
1
,
offset
=
0
,
size
=
10
):
"""
帖子详情页的榜单推荐
先获取该帖子所属榜单 过滤下线的无帖子的被删除的榜单
再根据该帖子下的标签去获取有这些标签的榜单
最后根据该标签对应的分类标签去获取榜单
:remark 入选画报
:param user_id:
:param sort_type:
...
...
@@ -108,7 +113,7 @@ def pictorial_topic(topic_id=-1, offset=0, size=10):
# 获取es链接对象
es_cli_obj
=
ESPerform
.
get_cli
()
q
=
{}
# 获取帖子
从属的画报
# 获取帖子
及该帖子的标签
q
[
"query"
]
=
{
"bool"
:
{
"must"
:
[
...
...
@@ -143,26 +148,30 @@ def pictorial_topic(topic_id=-1, offset=0, size=10):
for
item
in
result_dict
[
"hits"
]:
pict_pictorial_ids_list
=
item
[
"_source"
][
"pictorial_id"
]
topic_tag_list
=
item
[
"_source"
][
"tag_list"
]
##先拿到当前帖子对应的标签的分类ID
tag_type_ids
=
CommunityCategoryTagRelation
.
objects
.
filter
(
tag_id__in
=
topic_tag_list
,
is_online
=
True
,
is_deleted
=
False
)
.
values_list
(
"category_tag_id"
,
flat
=
True
)
logging
.
info
(
"get tag_type_ids:
%
s"
%
tag_type_ids
)
# 拿到所属榜单
if
len
(
pict_pictorial_ids_list
)
>
0
:
q
[
"query"
]
=
{
"bool"
:
{
"must"
:
[{
"terms"
:
{
"id"
:
pict_pictorial_ids_list
}
},
{
"term"
:
{
"is_online"
:
True
}
},
{
"term"
:
{
"is_deleted"
:
False
}
},
]
}
...
...
@@ -183,13 +192,18 @@ def pictorial_topic(topic_id=-1, offset=0, size=10):
pictorial_id
=
item
[
"_source"
][
"id"
]
pictorial_id_list
.
append
(
pictorial_id
)
if
len
(
pictorial_id_list
)
<
10
:
functions_list
=
[]
all_tag
=
[]
all_tag
.
extend
(
topic_tag_list
)
all_tag
.
extend
(
tag_type_ids
)
# 如果不够10个去拿所属标签的榜单和所属分类的标签的榜单
if
len
(
pictorial_id_list
)
<
10
and
len
(
all_tag
)
>
0
:
num
=
10
-
len
(
pictorial_id_list
)
q
[
"query"
]
=
{
q
uery
=
{
"bool"
:
{
"must"
:
[{
"terms"
:
{
"tag_id"
:
topic_tag_list
"tag_id"
:
all_tag
}},
{
"term"
:
{
"is_online"
:
True
...
...
@@ -208,31 +222,56 @@ def pictorial_topic(topic_id=-1, offset=0, size=10):
}]
}
}
functions_list
.
append
({
"filter"
:
{
"constant_score"
:
{
"filter"
:
{
"terms"
:
{
"tag_id"
:
topic_tag_list
}
}
}
},
"weight"
:
200
})
q
=
{
"query"
:
{
"function_score"
:
{
"query"
:
query
,
"score_mode"
:
"sum"
,
"boost_mode"
:
"replace"
,
"functions"
:
functions_list
}
}
}
q
[
"_source"
]
=
{
"includes"
:
[
"id"
,
"tag_id"
]}
q
[
"sort"
]
=
{
q
[
"sort"
]
=
[
{
"_score"
:
{
"order"
:
"desc"
}
},
{
'update_time'
:
{
'order'
:
'desc'
}}
q
[
"from"
]
=
0
q
[
"size"
]
=
10
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"pictorial"
,
q
,
offset
,
size
)
}
}
]
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"pictorial"
,
q
,
0
,
10
)
logging
.
info
(
"get result_dict:
%
s"
%
result_dict
)
if
len
(
result_dict
[
"hits"
])
>
0
:
for
item
in
result_dict
[
"hits"
]:
id
=
item
[
"_source"
][
"id"
]
if
id
not
in
pictorial_id_list
:
pictorial_id_list
.
append
(
id
)
#
pictorial_list
=
pictorial_id_list
if
len
(
pictorial_id_list
)
<
10
else
pictorial_id_list
[:
10
]
return
{
"pictorial_ids_list"
:
pictorial_list
}
else
:
return
{
"pictorial_ids_list"
:
pictorial_id_list
}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"pictorial_ids_list"
:
[]}
...
...
search/views/topic.py
View file @
3fec999d
...
...
@@ -15,6 +15,7 @@ from libs.es import ESPerform
from
django.conf
import
settings
from
libs.tools
import
get_have_read_lin_pictorial_id_list
import
datetime
from
trans2es.models.tag
import
Tag
def
get_discover_page_topic_ids
(
user_id
,
device_id
,
size
,
query_type
=
TopicPageType
.
FIND_PAGE
):
...
...
@@ -430,18 +431,47 @@ def topic_detail_page_recommend(device_id="", user_id=-1, topic_id=-1, topic_pic
have_read_topic_list
.
append
(
topic_id
)
topic_user_result
=
list
()
topic_tag_result
=
list
()
normal_tag_result
=
list
()
category_tag_reuslt
=
list
()
result
=
list
()
if
len
(
topic_tag_list
)
!=
0
:
topic_tag_result
=
TopicUtils
.
top_get_topic_detail_recommend_list
(
user_id
,
topic_id
,
have_read_topic_list
,
tag_query_results
=
Tag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
id__in
=
topic_tag_list
,
is_online
=
True
,
is_deleted
=
False
)
.
values_list
(
"id"
,
"is_category"
)
category_tag_list
=
list
()
normal_tag_list
=
list
()
for
id
,
is_category
in
tag_query_results
:
if
is_category
:
category_tag_list
.
append
(
id
)
else
:
normal_tag_list
.
append
(
id
)
if
len
(
normal_tag_list
)
!=
0
:
normal_tag_result
=
TopicUtils
.
top_get_topic_detail_recommend_list
(
user_id
,
topic_id
,
have_read_topic_list
,
size
,
es_cli_obj
,
index_type
=
"topic"
,
routing
=
"3,4,5,6"
,
topic_tag_list
=
topic
_tag_list
)
topic_tag_size
=
len
(
topic
_tag_result
)
have_read_topic_list
.
extend
(
topic
_tag_result
)
topic_tag_list
=
normal
_tag_list
)
normal_tag_size
=
len
(
normal
_tag_result
)
have_read_topic_list
.
extend
(
normal
_tag_result
)
else
:
topic_tag_size
=
0
if
topic_tag_size
<
size
:
size
=
size
-
topic_tag_size
normal_tag_size
=
0
if
normal_tag_size
<
size
:
size
=
size
-
normal_tag_size
if
len
(
category_tag_list
)
!=
0
:
category_tag_reuslt
=
TopicUtils
.
top_get_topic_detail_recommend_list
(
user_id
,
topic_id
,
have_read_topic_list
,
size
,
es_cli_obj
,
index_type
=
"topic"
,
routing
=
"3,4,5,6"
,
topic_tag_list
=
category_tag_list
)
category_tag_size
=
len
(
category_tag_reuslt
)
have_read_topic_list
.
extend
(
category_tag_reuslt
)
else
:
category_tag_size
=
0
if
category_tag_size
<
size
:
size
=
size
-
category_tag_size
if
topic_user_id
!=
-
1
:
topic_user_result
=
TopicUtils
.
top_get_topic_detail_recommend_list
(
user_id
,
topic_id
,
have_read_topic_list
,
...
...
@@ -494,7 +524,8 @@ def topic_detail_page_recommend(device_id="", user_id=-1, topic_id=-1, topic_pic
logging
.
warning
(
"topic_user_result:
%
s"
%
str
(
topic_user_result
))
logging
.
warning
(
"result:
%
s"
%
str
(
result
))
recommend_topic_ids_list
=
list
()
recommend_topic_ids_list
.
extend
(
topic_tag_result
)
recommend_topic_ids_list
.
extend
(
normal_tag_result
)
recommend_topic_ids_list
.
extend
(
category_tag_reuslt
)
recommend_topic_ids_list
.
extend
(
topic_user_result
)
recommend_topic_ids_list
.
extend
(
result
)
return
{
"recommend_topic_ids"
:
recommend_topic_ids_list
}
...
...
trans2es/models/tag.py
View file @
3fec999d
...
...
@@ -53,6 +53,7 @@ class Tag(models.Model):
is_own
=
models
.
IntegerField
(
verbose_name
=
u"是否ins上自带"
)
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_category
=
models
.
IntegerField
(
verbose_name
=
u"是否大分类"
)
class
CommunityTagFollow
(
models
.
Model
):
...
...
trans2es/models/topic.py
View file @
3fec999d
...
...
@@ -441,7 +441,6 @@ class CommunityTopicProduct(models.Model):
create_time
=
models
.
DateTimeField
(
verbose_name
=
u'创建时间'
)
is_deleted
=
models
.
BooleanField
(
verbose_name
=
u'是否删除'
)
class
CommunityCategoryTagRelation
(
models
.
Model
):
class
Meta
:
verbose_name
=
u"标签分类对应关系"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment