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
8c0f8626
Commit
8c0f8626
authored
Apr 19, 2019
by
黄凯
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'hk' into 'test'
add topic detail See merge request alpha/physical!292
parents
ee1d17ec
167b05e2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
26 deletions
+54
-26
topic.py
search/utils/topic.py
+26
-2
topic.py
search/views/topic.py
+28
-24
No files found.
search/utils/topic.py
View file @
8c0f8626
...
...
@@ -122,7 +122,7 @@ class TopicUtils(object):
@classmethod
def
get_recommend_topic_ids
(
cls
,
user_id
,
tag_id
,
offset
,
size
,
single_size
,
query
=
None
,
query_type
=
TopicPageType
.
FIND_PAGE
,
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
=
[]):
user_similar_score_list
=
[],
index_type
=
"topic"
,
routing
=
None
,
attention_tag_list
=
[]
,
current_topic_id
=-
1
,
topic_tag_list
=
[],
topic_user_id
=-
1
):
"""
:remark:获取首页推荐帖子列表
:param user_id:
...
...
@@ -204,6 +204,25 @@ class TopicUtils(object):
"weight"
:
100
}
)
if
current_topic_id
!=
-
1
:
if
len
(
topic_tag_list
)
>
0
:
functions_list
.
append
(
{
"filter"
:
{
"bool"
:
{
"should"
:
{
"terms"
:
{
"tag_list"
:
topic_tag_list
}}}},
"weight"
:
10000
}
)
if
topic_user_id
!=
-
1
:
functions_list
.
append
(
{
"filter"
:
{
"bool"
:
{
"should"
:
{
"term"
:
{
"user_id"
:
topic_user_id
}}}},
"weight"
:
5000
}
)
query_function_score
=
{
"query"
:
{
"bool"
:
{
...
...
@@ -246,7 +265,12 @@ class TopicUtils(object):
query_function_score
[
"query"
][
"bool"
][
"must_not"
]
=
[
{
"terms"
:{
"id"
:
filter_topic_id_list
}}
]
if
current_topic_id
!=
-
1
:
query_function_score
[
"query"
][
"bool"
][
"must_not"
]
=
{
"term"
:
{
"id"
:
current_topic_id
}
}
if
query
is
not
None
:
# 搜索帖子
multi_fields
=
{
'description'
:
200
,
...
...
search/views/topic.py
View file @
8c0f8626
...
...
@@ -253,7 +253,7 @@ def home_query(device_id="", tag_id=-1, user_id=-1, query="", offset=0, size=10)
@bind
(
"physical/search/topic_detail_page_recommend"
)
def
topic_detail_page_recommend
(
device_id
=
""
,
user_id
=-
1
,
topic_id
=-
1
,
topic_pictorial_id
=-
1
,
topic_user_id
=-
1
,
filter_topic_user_id
=
False
,
offset
=
0
,
size
=
10
):
filter_topic_user_id
=
False
,
offset
=
0
,
size
=
10
,
topic_tag_list
=
[]
):
"""
:remark:帖子详情页推荐策略,缺少第一个卡片策略
:param user_id:
...
...
@@ -266,30 +266,34 @@ def topic_detail_page_recommend(device_id="", user_id=-1, topic_id=-1, topic_pic
if
not
isinstance
(
user_id
,
int
):
user_id
=
-
1
redis_key
=
"physical:topic_detail_page_recommend"
+
":user_id:"
+
str
(
user_id
)
+
":device_id:"
+
str
(
device_id
)
have_read_topic_redis_data
=
redis_client
.
get
(
redis_key
)
have_read_topic_list
=
json
.
loads
(
have_read_topic_redis_data
)
if
have_read_topic_redis_data
else
[]
# 获取es链接对象
es_cli_obj
=
ESPerform
.
get_cli
()
# 获取帖子标签列表
topic_tag_list
=
TopicUtils
.
get_topic_tag_id_list
(
topic_id
,
es_cli_obj
)
result_list
=
TopicUtils
.
get_topic_detail_recommend_list
(
user_id
,
topic_id
,
topic_tag_list
,
topic_pictorial_id
,
topic_user_id
,
filter_topic_user_id
,
have_read_topic_list
,
offset
,
size
,
es_cli_obj
,
index_type
=
"topic"
,
routing
=
"4,5,6"
)
# redis_key = "physical:topic_detail_page_recommend" + ":user_id:" + str(user_id) + ":device_id:" + str(device_id)
# have_read_topic_redis_data = redis_client.get(redis_key)
# have_read_topic_list = json.loads(have_read_topic_redis_data) if have_read_topic_redis_data else []
#
# # 获取es链接对象
# es_cli_obj = ESPerform.get_cli()
#
# # 获取帖子标签列表
# topic_tag_list = TopicUtils.get_topic_tag_id_list(topic_id, es_cli_obj)
# result_list = TopicUtils.get_topic_detail_recommend_list(user_id, topic_id, topic_tag_list, topic_pictorial_id,
# topic_user_id, filter_topic_user_id,
# have_read_topic_list, offset, size, es_cli_obj,index_type="topic",routing="4,5,6")
result_list
=
TopicUtils
.
get_recommend_topic_ids
(
user_id
,
tag_id
=-
1
,
single_size
=
size
,
offset
=
offset
,
size
=
size
,
topic_user_id
=
topic_user_id
,
current_topic_id
=
topic_id
,
topic_tag_list
=
topic_tag_list
)
recommend_topic_ids_list
=
list
()
if
len
(
result_list
)
>
0
:
recommend_topic_ids_list
=
[
item
[
"_source"
][
"id"
]
for
item
in
result_list
]
have_read_topic_list
.
extend
(
recommend_topic_ids_list
)
have_read_topic_len
=
len
(
have_read_topic_list
)
if
have_read_topic_len
>
5000
:
have_read_topic_list
=
have_read_topic_list
[(
have_read_topic_len
-
5000
):]
redis_client
.
set
(
redis_key
,
json
.
dumps
(
have_read_topic_list
))
# if len(result_list) > 0:
# recommend_topic_ids_list = [item["_source"]["id"] for item in result_list]
recommend_topic_ids_list
.
extend
(
result_list
)
#
# have_read_topic_list.extend(recommend_topic_ids_list)
#
# have_read_topic_len = len(have_read_topic_list)
# if have_read_topic_len > 5000:
# have_read_topic_list = have_read_topic_list[(have_read_topic_len - 5000):]
#
# redis_client.set(redis_key, json.dumps(have_read_topic_list))
return
{
"recommend_topic_ids"
:
recommend_topic_ids_list
}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
...
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