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
badb8ad5
Commit
badb8ad5
authored
Jan 24, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify bug
parent
ac2a1e01
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
31 deletions
+31
-31
topic.py
search/utils/topic.py
+6
-5
topic.py
search/views/topic.py
+25
-26
No files found.
search/utils/topic.py
View file @
badb8ad5
...
...
@@ -238,13 +238,14 @@ class TopicUtils(object):
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
"topic"
,
query_body
=
q
,
offset
=
offset
,
size
=
size
)
if
len
(
result_dict
[
"hits"
])
>
0
:
return
[
item
[
"_source"
]
for
item
in
result_dict
[
"hits"
]]
else
:
return
[]
topic_id_dict
=
dict
()
for
item
in
result_dict
[
"hits"
]:
topic_id_dict
[
item
[
"_source"
][
"id"
]]
=
item
[
"_source"
][
"group_id"
]
return
topic_id_dict
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
return
dict
()
@classmethod
def
get_topic_detail_recommend_list
(
cls
,
user_id
,
topic_id
,
topic_tag_list
,
topic_group_id
,
topic_user_id
,
filter_topic_user_id
,
offset
,
size
,
es_cli_obj
=
None
):
...
...
search/views/topic.py
View file @
badb8ad5
...
...
@@ -26,10 +26,10 @@ def get_discover_page_topic_ids(user_id,device_id,size,query_type=TopicPageType.
have_read_topic_id_list
=
json
.
loads
(
redis_field_val_list
[
0
])
if
redis_field_val_list
[
0
]
else
[]
recommend_topic_ids
=
[]
topic_id_
lis
t
=
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
)
topic_id_
dic
t
=
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_lis
t
:
recommend_topic_ids
.
append
(
item
[
"id"
]
)
for
topic_id
in
topic_id_dic
t
:
recommend_topic_ids
.
append
(
topic_id
)
have_read_topic_id_list
.
extend
(
recommend_topic_ids
)
redis_dict
=
{
...
...
@@ -63,17 +63,17 @@ def get_home_recommend_topic_ids(user_id,device_id,offset,size,query=None,query_
last_offset_num
=
int
(
redis_field_val_list
[
0
])
if
redis_field_val_list
[
0
]
else
-
1
recommend_topic_ids
=
[]
topic_id_
lis
t
=
TopicUtils
.
get_recommend_topic_ids
(
user_id
,
offset
,
size
*
size
,
query
,
query_type
=
query_type
)
topic_id_
dic
t
=
TopicUtils
.
get_recommend_topic_ids
(
user_id
,
offset
,
size
*
size
,
query
,
query_type
=
query_type
)
have_read_group_id_set
=
set
()
unread_topic_id_
list
=
lis
t
()
unread_topic_id_
dict
=
dic
t
()
have_read_topic_id_set
=
set
()
ori_unread_topic_id_
lis
t
=
list
()
ori_unread_topic_id_
dic
t
=
list
()
if
redis_field_val_list
[
1
]
and
offset
>
0
:
if
(
user_id
>
0
and
offset
==
last_offset_num
)
or
user_id
==-
1
:
ori_unread_topic_id_
lis
t
=
json
.
loads
(
redis_field_val_list
[
1
])
topic_id_
list
=
ori_unread_topic_id_list
+
topic_id_list
ori_unread_topic_id_
dic
t
=
json
.
loads
(
redis_field_val_list
[
1
])
topic_id_
dict
=
ori_unread_topic_id_dict
.
update
(
topic_id_dict
)
for
have_read_item
in
redis_field_val_list
[
2
:]:
if
have_read_item
:
...
...
@@ -84,36 +84,35 @@ def get_home_recommend_topic_ids(user_id,device_id,offset,size,query=None,query_
# 当前页用户数量
cur_page_user_num
=
0
for
item
in
topic_id_lis
t
:
if
item
[
"group_id"
]
in
have_read_group_id_set
:
unread_topic_id_
list
.
append
(
item
)
for
topic_id
in
topic_id_dic
t
:
if
topic_id_dict
[
topic_id
]
in
have_read_group_id_set
:
unread_topic_id_
dict
[
topic_id
]
=
topic_id_dict
[
topic_id
]
else
:
if
item
[
"id"
]
not
in
have_read_topic_id_set
:
if
isinstance
(
item
[
"group_id"
],
int
)
and
item
[
"group_id"
]
>
0
and
cur_page_group_num
<
(
size
*
0.9
):
have_read_group_id_set
.
add
(
item
[
"group_id"
])
have_read_topic_id_set
.
add
(
item
[
"id"
]
)
if
topic_id
not
in
have_read_topic_id_set
:
if
isinstance
(
topic_id_dict
[
topic_id
],
int
)
and
topic_id_dict
[
topic_id
]
>
0
and
cur_page_group_num
<
(
size
*
0.9
):
have_read_group_id_set
.
add
(
topic_id_dict
[
topic_id
])
have_read_topic_id_set
.
add
(
topic_id
)
cur_page_group_num
+=
1
recommend_topic_ids
.
append
(
item
[
"id"
]
)
elif
item
[
"group_id"
]
<=
0
and
cur_page_user_num
<
(
size
*
0.1
):
recommend_topic_ids
.
append
(
topic_id
)
elif
topic_id_dict
[
topic_id
]
and
cur_page_user_num
<
(
size
*
0.1
):
cur_page_user_num
+=
1
recommend_topic_ids
.
append
(
item
[
"id"
]
)
recommend_topic_ids
.
append
(
topic_id
)
else
:
unread_topic_id_
list
.
append
(
item
)
unread_topic_id_
dict
[
topic_id
]
=
topic_id_dict
[
topic_id
]
if
len
(
recommend_topic_ids
)
>=
size
:
break
if
len
(
recommend_topic_ids
)
<
size
and
len
(
unread_topic_id_
lis
t
)
>
0
:
if
len
(
recommend_topic_ids
)
<
size
and
len
(
unread_topic_id_
dic
t
)
>
0
:
recommend_len
=
len
(
recommend_topic_ids
)
offi_unread_topic_id
=
[
item
[
"id"
]
for
item
in
unread_topic_id_list
[:(
size
-
recommend_len
)]]
recommend_topic_ids
=
recommend_topic_ids
+
offi_unread_topic_id
unread_topic_id_list
=
unread_topic_id_list
[(
size
-
recommend_len
):]
for
unread_topic_id
in
unread_topic_id_dict
:
if
len
(
recommend_topic_ids
)
<
size
:
recommend_topic_ids
.
append
(
unread_topic_id
)
unread_topic_id_dict
.
pop
(
unread_topic_id
)
if
user_id
==-
1
:
unread_topic_id_list
=
ori_unread_topic_id_list
+
unread_topic_id_list
redis_dict
=
{
"unread_topic_id"
:
json
.
dumps
(
unread_topic_id_
lis
t
),
"unread_topic_id"
:
json
.
dumps
(
unread_topic_id_
dic
t
),
"last_offset_num"
:
offset
+
size
,
offset
:
json
.
dumps
(
recommend_topic_ids
)
}
...
...
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