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
ba9eca6c
Commit
ba9eca6c
authored
Apr 22, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'test' of git.wanmeizhensuo.com:alpha/physical into test
parents
32e5a81a
94907185
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
166 additions
and
15 deletions
+166
-15
topic.py
search/utils/topic.py
+100
-1
topic.py
search/views/topic.py
+66
-14
No files found.
search/utils/topic.py
View file @
ba9eca6c
...
...
@@ -220,7 +220,7 @@ class TopicUtils(object):
{
"filter"
:
{
"bool"
:
{
"should"
:
{
"term"
:
{
"user_id"
:
topic_user_id
}}}},
"weight"
:
100
000
"weight"
:
5
000
}
)
query_function_score
=
{
...
...
@@ -425,6 +425,105 @@ class TopicUtils(object):
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
@classmethod
def
top_get_topic_detail_recommend_list
(
cls
,
user_id
,
topic_id
,
have_read_topic_list
,
size
,
es_cli_obj
=
None
,
index_type
=
"topic"
,
routing
=
None
,
collection_topic_tag_list
=
[],
topic_tag_list
=
[],
topic_user_id
=-
1
):
"""
:remark 帖子详情页推荐列表,缺少按时间衰减
:param user_id:
:param topic_tag_list:
:param topic_group_id:
:param topic_user_id:
:param offset:
:param size:
:return:
"""
try
:
if
not
es_cli_obj
:
es_cli_obj
=
ESPerform
.
get_cli
()
q
=
dict
()
q
[
"query"
]
=
dict
()
functions_list
=
[
{
"linear"
:
{
"create_time"
:
{
"scale"
:
"1d"
,
"decay"
:
0.5
}
}
}
]
if
len
(
topic_tag_list
)
!=
0
or
user_id
!=
-
1
:
query_function_score
=
{
"query"
:
{
"bool"
:
{
"must"
:
[
{
"range"
:
{
"content_level"
:
{
"gte"
:
3
,
"lte"
:
6
}}},
{
"term"
:
{
"is_online"
:
True
}},
{
"term"
:
{
"is_deleted"
:
False
}}
],
"must_not"
:
{
"terms"
:
{
"id"
:
have_read_topic_list
}
}
}
},
"score_mode"
:
"sum"
,
"boost_mode"
:
"sum"
,
"functions"
:
functions_list
}
else
:
query_function_score
=
{
"query"
:
{
"bool"
:
{
"must"
:
[
{
"range"
:
{
"content_level"
:
{
"gte"
:
4
,
"lte"
:
6
}}},
{
"term"
:
{
"is_online"
:
True
}},
{
"term"
:
{
"is_deleted"
:
False
}}
],
"must_not"
:
{
"terms"
:
{
"id"
:
have_read_topic_list
}
}
}
},
"score_mode"
:
"sum"
,
"boost_mode"
:
"sum"
,
"functions"
:
functions_list
}
if
len
(
topic_tag_list
)
>
0
:
query_function_score
[
"query"
][
"bool"
][
"should"
]
=
{
"terms"
:
{
"tag_list"
:
topic_tag_list
}
}
if
topic_user_id
!=
-
1
:
query_function_score
[
"query"
][
"bool"
][
"should"
]
=
{
"term"
:
{
"user_id"
:
topic_user_id
}
}
q
[
"query"
][
"function_score"
]
=
query_function_score
q
[
"_source"
]
=
{
"includes"
:
[
"id"
,
"pictorial_id"
,
"user_id"
,
"_score"
]
}
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
sub_index_name
=
index_type
,
query_body
=
q
,
size
=
size
,
routing
=
routing
)
topic_id_list
=
list
()
for
item
in
result_dict
[
"hits"
]:
topic_id_list
.
append
(
item
[
"_source"
][
"id"
])
return
topic_id_list
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
@classmethod
def
get_topic_tag_id_list
(
cls
,
topic_id
,
es_cli_obj
=
None
):
"""
...
...
search/views/topic.py
View file @
ba9eca6c
...
...
@@ -265,7 +265,56 @@ def topic_detail_page_recommend(device_id="", user_id=-1, topic_id=-1, topic_pic
try
:
if
not
isinstance
(
user_id
,
int
):
user_id
=
-
1
if
user_id
>
0
:
redis_key
=
"physical:topic_detail_recommend"
+
":user_id:"
+
str
(
user_id
)
+
"topic_id:"
+
str
(
topic_id
)
else
:
redis_key
=
"physical:topic_detail_recommend"
+
":device_id:"
+
device_id
+
"topic_id:"
+
str
(
topic_id
)
if
offset
==
0
:
have_read_topic_list
=
list
()
# redis_dict = {
# "have_read_topic_id": json.dumps(have_read_topic_list)
# }
redis_client
.
delete
(
redis_key
)
# redis_client.expire(redis_key, 60 * 60 * 24)
else
:
have_read_topic_list
=
list
()
redis_field_list
=
[
b
'have_read_topic_list'
]
have_read_topic_redis_data
=
redis_client
.
hmget
(
redis_key
,
redis_field_list
)
have_read_topic_list
=
json
.
loads
(
have_read_topic_redis_data
[
0
])
if
have_read_topic_redis_data
[
0
]
else
[]
es_cli_obj
=
ESPerform
.
get_cli
()
have_read_topic_list
.
append
(
topic_id
)
topic_user_result
=
list
()
topic_tag_result
=
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
,
size
,
es_cli_obj
,
index_type
=
"topic"
,
routing
=
"4,5,6"
,
topic_tag_list
=
topic_tag_list
)
topic_tag_size
=
len
(
topic_tag_result
)
have_read_topic_list
.
extend
(
topic_tag_result
)
else
:
topic_tag_size
=
0
if
topic_tag_size
<
size
:
size
=
size
-
topic_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
,
size
,
es_cli_obj
,
index_type
=
"topic"
,
routing
=
"4,5,6"
,
topic_tag_list
=
topic_tag_list
)
topic_user_size
=
len
(
topic_user_result
)
have_read_topic_list
.
extend
(
topic_user_result
)
if
topic_user_size
<
size
:
size
=
size
-
topic_user_size
result
=
TopicUtils
.
top_get_topic_detail_recommend_list
(
user_id
,
topic_id
,
have_read_topic_list
,
size
,
es_cli_obj
,
index_type
=
"topic"
,
routing
=
"4,5,6"
)
have_read_topic_list
.
extend
(
result
)
# 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 []
#
# 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 []
...
...
@@ -279,21 +328,24 @@ def topic_detail_page_recommend(device_id="", user_id=-1, topic_id=-1, topic_pic
# 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]
recommend_topic_ids_list
.
extend
(
result_list
)
#
# have_read_topic_list.extend(recommend_topic_ids_list)
# 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)
#
# 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))
# user_recommend_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)
redis_dict
=
{
"have_read_topic_list"
:
json
.
dumps
(
have_read_topic_list
),
}
redis_client
.
hmset
(
redis_key
,
redis_dict
)
redis_client
.
expire
(
redis_key
,
60
*
60
*
24
)
result_list
=
[]
recommend_topic_ids_list
=
list
()
recommend_topic_ids_list
.
extend
(
topic_tag_result
)
recommend_topic_ids_list
.
extend
(
topic_user_result
)
recommend_topic_ids_list
.
extend
(
result
)
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