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
0e06252e
Commit
0e06252e
authored
Jan 17, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
468b08e0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
13 deletions
+77
-13
topic.py
search/utils/topic.py
+7
-1
topic.py
search/views/topic.py
+70
-12
No files found.
search/utils/topic.py
View file @
0e06252e
...
...
@@ -90,7 +90,7 @@ class TopicUtils(object):
return
[]
@classmethod
def
get_recommend_topic_ids
(
cls
,
user_id
,
offset
,
size
,
query
=
None
,
query_type
=
TopicPageType
.
HOME_RECOMMEND
):
def
get_recommend_topic_ids
(
cls
,
user_id
,
offset
,
size
,
query
=
None
,
query_type
=
TopicPageType
.
HOME_RECOMMEND
,
filter_topic_id_list
=
[]
):
"""
:需增加打散逻辑
:remark:获取首页推荐帖子列表
...
...
@@ -190,6 +190,12 @@ class TopicUtils(object):
"boost_mode"
:
"sum"
,
"functions"
:
functions_list
}
if
query_type
==
TopicPageType
.
FIND_PAGE
and
len
(
filter_topic_id_list
)
>
0
:
query_function_score
[
"query"
][
"bool"
][
"must_not"
]
=
{
"terms"
:{
"id"
:
filter_topic_id_list
}
}
if
query
is
not
None
:
#搜索帖子
multi_fields
=
{
...
...
search/views/topic.py
View file @
0e06252e
...
...
@@ -12,12 +12,47 @@ from libs.cache import redis_client
from
search.utils.common
import
*
def
get_home_recommend_topic_ids
(
user_id
,
session_id
,
offset
,
size
,
query
=
None
,
query_type
=
TopicPageType
.
HOME_RECOMMEND
):
def
get_discover_page_topic_ids
(
user_id
,
device_id
,
size
,
query_type
=
TopicPageType
.
HOME_RECOMMEND
):
try
:
if
user_id
==
-
1
:
redis_key
=
"physical:discover_page"
+
":user_id:"
+
str
(
user_id
)
+
":device_id:"
+
device_id
else
:
redis_key
=
"physical:discover_page"
+
":user_id:"
+
str
(
user_id
)
redis_field_list
=
[
b
'have_read_topic_id'
]
redis_field_val_list
=
redis_client
.
hmget
(
redis_key
,
redis_field_list
)
have_read_topic_id_list
=
json
.
loads
(
redis_field_val_list
[
0
])
recommend_topic_ids
=
[]
topic_id_list
=
TopicUtils
.
get_recommend_topic_ids
(
user_id
=
user_id
,
offset
=
0
,
size
=
size
,
query_type
=
query_type
,
filter_topic_id_list
=
have_read_topic_id_list
)
for
item
in
topic_id_list
:
recommend_topic_ids
.
append
(
item
[
"id"
])
have_read_topic_id_list
.
extend
(
recommend_topic_ids
)
redis_dict
=
{
"have_read_topic_id"
:
json
.
dumps
(
have_read_topic_id_list
)
}
redis_client
.
hmset
(
redis_key
,
redis_dict
)
return
recommend_topic_ids
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
def
get_home_recommend_topic_ids
(
user_id
,
device_id
,
offset
,
size
,
query
=
None
,
query_type
=
TopicPageType
.
HOME_RECOMMEND
):
try
:
if
query
is
None
:
redis_key
=
"physical:home_recommend"
+
":user_id:"
+
str
(
user_id
)
+
":session_id:"
+
session_id
+
":query_type:"
+
str
(
query_type
)
if
user_id
==
-
1
:
redis_key
=
"physical:home_recommend"
+
":user_id:"
+
str
(
user_id
)
+
":device_id:"
+
device_id
+
":query_type:"
+
str
(
query_type
)
else
:
redis_key
=
"physical:home_recommend"
+
":user_id:"
+
str
(
user_id
)
+
":query_type:"
+
str
(
query_type
)
else
:
redis_key
=
"physical:home_query"
+
":user_id:"
+
str
(
user_id
)
+
":session_id:"
+
session_id
+
":query:"
+
str
(
query
)
+
":query_type:"
+
str
(
query_type
)
if
user_id
==
-
1
:
redis_key
=
"physical:home_query"
+
":user_id:"
+
str
(
user_id
)
+
":device_id:"
+
device_id
+
":query:"
+
str
(
query
)
+
":query_type:"
+
str
(
query_type
)
else
:
redis_key
=
"physical:home_query"
+
":user_id:"
+
str
(
user_id
)
+
":query:"
+
str
(
query
)
+
":query_type:"
+
str
(
query_type
)
redis_field_list
=
[
b
'last_offset_num'
,
b
'unread_topic_id'
]
for
page_id
in
range
(
0
,
offset
,
size
):
...
...
@@ -90,9 +125,32 @@ def get_home_recommend_topic_ids(user_id,session_id,offset,size,query=None,query
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
@bind
(
"physical/search/home_recommend"
)
def
home_recommend
(
session_id
=
""
,
user_id
=-
1
,
offset
=
0
,
size
=
10
,
query_type
=
TopicPageType
.
HOME_RECOMMEND
):
def
home_recommend
(
device_id
=
""
,
user_id
=-
1
,
offset
=
0
,
size
=
10
,
query_type
=
TopicPageType
.
HOME_RECOMMEND
):
"""
:remark:首页推荐,目前只推荐日记
:param session_id:
:param user_id:
:param offset:
:param size:
:return:
"""
try
:
if
not
user_id
:
user_id
=-
1
if
not
isinstance
(
device_id
,
str
):
device_id
=
""
recommend_topic_ids
=
get_home_recommend_topic_ids
(
user_id
,
device_id
,
offset
,
size
,
query_type
=
query_type
)
return
{
"recommend_topic_ids"
:
recommend_topic_ids
}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"recommend_topic_ids"
:
[]}
@bind
(
"physical/search/discover_page"
)
def
discover_page
(
device_id
=
""
,
user_id
=-
1
,
size
=
10
):
"""
:remark:首页推荐,目前只推荐日记
:param session_id:
...
...
@@ -104,10 +162,10 @@ def home_recommend(session_id="",user_id=-1,offset=0,size=10,query_type=TopicPag
try
:
if
not
user_id
:
user_id
=-
1
if
not
isinstance
(
session
_id
,
str
):
session_id
=
""
# if not isinstance(device
_id,str):
#
session_id = ""
recommend_topic_ids
=
get_
home_recommend_topic_ids
(
user_id
,
session_id
,
offset
,
size
,
query_type
=
query_type
)
recommend_topic_ids
=
get_
discover_page_topic_ids
(
user_id
,
device_id
,
size
,
query_type
=
TopicPageType
.
HOME_RECOMMEND
)
return
{
"recommend_topic_ids"
:
recommend_topic_ids
}
except
:
...
...
@@ -116,7 +174,7 @@ def home_recommend(session_id="",user_id=-1,offset=0,size=10,query_type=TopicPag
@bind
(
"physical/search/home_query"
)
def
home_query
(
session
_id
=
""
,
user_id
=-
1
,
query
=
""
,
offset
=
0
,
size
=
10
):
def
home_query
(
device
_id
=
""
,
user_id
=-
1
,
query
=
""
,
offset
=
0
,
size
=
10
):
"""
:remark:首页搜索,目前只推荐日记
:param session_id:
...
...
@@ -129,10 +187,10 @@ def home_query(session_id="",user_id=-1,query="",offset=0,size=10):
try
:
if
not
user_id
:
user_id
=-
1
if
not
isinstance
(
session
_id
,
str
):
session
_id
=
""
if
not
isinstance
(
device
_id
,
str
):
device
_id
=
""
recommend_topic_ids
=
get_home_recommend_topic_ids
(
user_id
,
session
_id
,
offset
,
size
,
query
)
recommend_topic_ids
=
get_home_recommend_topic_ids
(
user_id
,
device
_id
,
offset
,
size
,
query
)
return
{
"recommend_topic_ids"
:
recommend_topic_ids
}
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