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
24529ca5
Commit
24529ca5
authored
Apr 18, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify home_recommend
parent
33ae89e9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
79 deletions
+36
-79
topic.py
search/utils/topic.py
+12
-54
topic.py
search/views/topic.py
+24
-25
No files found.
search/utils/topic.py
View file @
24529ca5
...
...
@@ -196,25 +196,6 @@ class TopicUtils(object):
"weight"
:
30
,
}
)
# if len(pick_user_id_list) > 0:
# functions_list.append(
# {
# "filter": {"bool": {
# "should": {"terms": {"user_id": pick_user_id_list}}}},
# "weight": 2
# }
# )
# if len(same_pictorial_id_list) > 0:
# functions_list.append(
# {
# "filter": {"bool": {
# "should": {"terms": {"user_id": same_pictorial_id_list}}}},
# "weight": 1
# }
# )
# query_tag_term_list = cls.___get_should_term_list(user_tag_list)
if
len
(
attention_tag_list
)
>
0
:
functions_list
.
append
(
{
...
...
@@ -223,35 +204,6 @@ class TopicUtils(object):
"weight"
:
100
}
)
# if len(recommend_tag_list)>0:
# if len(recommend_tag_list)>1:
# functions_list += [
# {
# "filter": {"term": {"tag_list": recommend_tag_list[0]}},
# "weight": 4
# },
# {
# "filter": {"terms": {"tag_list": recommend_tag_list[1:]}},
# "weight": 3
# }
# ]
# else:
# functions_list.append(
# {
# "filter": {"terms": {"tag_list": recommend_tag_list}},
# "weight": 3
# }
# )
# for tag_id in recommend_tag_dict:
# functions_list.append(
# {
# "filter": {"term": {"tag_list": tag_id}},
# "weight": recommend_tag_dict[tag_id]
# }
# )
# low_content_level = 4 if query_type == TopicPageType.FIND_PAGE else 3
query_function_score
=
{
"query"
:
{
"bool"
:
{
...
...
@@ -291,11 +243,9 @@ class TopicUtils(object):
}
}
if
len
(
filter_topic_id_list
)
>
0
:
query_function_score
[
"query"
][
"bool"
][
"must_not"
]
=
{
"terms"
:
{
"id"
:
filter_topic_id_list
}
}
query_function_score
[
"query"
][
"bool"
][
"must_not"
]
=
[
{
"terms"
:{
"id"
:
filter_topic_id_list
}}
]
if
query
is
not
None
:
# 搜索帖子
multi_fields
=
{
...
...
@@ -317,7 +267,15 @@ class TopicUtils(object):
{
"term"
:
{
"tag_list"
:
tag_id
}}
]
query_function_score
[
"query"
][
"bool"
][
"minimum_should_match"
]
=
1
else
:
if
"must_not"
in
query_function_score
[
"query"
][
"bool"
]:
query_function_score
[
"query"
][
"bool"
][
"must_not"
]
+=
[
{
"term"
:
{
"is_operation_home_recommend"
:
True
}}
]
else
:
query_function_score
[
"query"
][
"bool"
][
"must_not"
]
=
[
{
"term"
:
{
"is_operation_home_recommend"
:
True
}}
]
q
[
"query"
][
"function_score"
]
=
query_function_score
q
[
"collapse"
]
=
{
"field"
:
"user_id"
...
...
search/views/topic.py
View file @
24529ca5
...
...
@@ -73,47 +73,46 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
if
offset
>
0
:
# 首次搜索时不需要过滤已读
have_read_topic_id_list
=
list
(
json
.
loads
(
redis_field_val_list
[
0
]))
# linucb 推荐帖子
topic_recommend_redis_key
=
"physical:linucb:topic_recommend:device_id:"
+
str
(
device_id
)
recommend_topic_list
=
list
()
recommend_topic_dict
=
redis_client
.
hgetall
(
topic_recommend_redis_key
)
if
b
"data"
in
recommend_topic_dict
:
recommend_topic_id_list
=
json
.
loads
(
recommend_topic_dict
[
b
"data"
])
# 推荐帖子是强插的,要保证推荐帖子不在已读里
recommend_topic_id_list
=
list
(
set
(
recommend_topic_id_list
)
-
set
(
have_read_topic_id_list
))
cursor
=
int
(
str
(
recommend_topic_dict
[
b
"cursor"
],
encoding
=
"utf-8"
))
newcursor
=
cursor
+
6
if
len
(
recommend_topic_id_list
)
>
newcursor
:
recommend_topic_list
=
recommend_topic_id_list
[
cursor
:
newcursor
]
redis_client
.
hset
(
topic_recommend_redis_key
,
"cursor"
,
newcursor
)
user_similar_score_redis_key
=
"physical:user_similar_score:user_id:"
+
str
(
user_id
)
redis_user_similar_score_redis_val
=
redis_client
.
get
(
user_similar_score_redis_key
)
user_similar_score_redis_list
=
json
.
loads
(
redis_user_similar_score_redis_val
)
if
redis_user_similar_score_redis_val
else
[]
recommend_topic_list
=
list
()
if
query
is
None
:
# linucb 推荐帖子
topic_recommend_redis_key
=
"physical:linucb:topic_recommend:device_id:"
+
str
(
device_id
)
recommend_topic_dict
=
redis_client
.
hgetall
(
topic_recommend_redis_key
)
if
b
"data"
in
recommend_topic_dict
:
recommend_topic_id_list
=
json
.
loads
(
recommend_topic_dict
[
b
"data"
])
# 推荐帖子是强插的,要保证推荐帖子不在已读里
recommend_topic_id_list
=
list
(
set
(
recommend_topic_id_list
)
-
set
(
have_read_topic_id_list
))
cursor
=
int
(
str
(
recommend_topic_dict
[
b
"cursor"
],
encoding
=
"utf-8"
))
newcursor
=
cursor
+
6
if
len
(
recommend_topic_id_list
)
>
newcursor
:
recommend_topic_list
=
recommend_topic_id_list
[
cursor
:
newcursor
]
redis_client
.
hset
(
topic_recommend_redis_key
,
"cursor"
,
newcursor
)
# 用户关注标签
redis_tag_data
=
redis_client
.
hget
(
"physical:linucb:register_user_tag_info"
,
user_id
)
attention_tag_list
=
json
.
loads
(
redis_tag_data
)
if
redis_tag_data
else
[]
if
len
(
recommend_topic_list
)
>
0
:
size
=
size
-
len
(
recommend_topic_list
)
have_read_topic_id_list
.
extend
(
recommend_topic_list
)
have_read_topic_id_list_add_promote
=
list
()
have_read_topic_id_list_add_promote
.
extend
(
have_read_topic_id_list
)
promote_recommend_topic_id_list
=
TopicHomeRecommend
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
is_online
=
1
)
.
values_list
(
"topic_id"
,
flat
=
True
)
for
topic_id
in
promote_recommend_topic_id_list
:
have_read_topic_id_list_add_promote
.
append
(
topic_id
)
#
have_read_topic_id_list_add_promote = list()
#
have_read_topic_id_list_add_promote.extend(have_read_topic_id_list)
#
promote_recommend_topic_id_list = TopicHomeRecommend.objects.using(settings.SLAVE_DB_NAME).filter(
#
is_online=1).values_list("topic_id",flat=True)
#
#
for topic_id in promote_recommend_topic_id_list:
#
have_read_topic_id_list_add_promote.append(topic_id)
topic_id_list
=
list
()
rank_topic_id_list
=
TopicUtils
.
get_recommend_topic_ids
(
user_id
=
user_id
,
tag_id
=
tag_id
,
offset
=
offset
,
size
=
size
,
single_size
=
size
,
query
=
query
,
query_type
=
query_type
,
filter_topic_id_list
=
have_read_topic_id_list_add_promote
,
recommend_tag_list
=
recommend_topic_list
,
filter_topic_id_list
=
have_read_topic_id_list
,
user_similar_score_list
=
user_similar_score_redis_list
,
index_type
=
"topic"
,
routing
=
"4,5,6"
,
attention_tag_list
=
attention_tag_list
)
if
len
(
recommend_topic_list
)
==
6
and
query
is
None
:
...
...
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