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
2ebbf249
Commit
2ebbf249
authored
Aug 21, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add
parent
adebab92
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
14 deletions
+31
-14
group.py
search/views/group.py
+31
-14
No files found.
search/views/group.py
View file @
2ebbf249
...
...
@@ -13,6 +13,7 @@ from libs.es import ESPerform
from
search.utils.group
import
GroupUtils
from
search.utils.common
import
GroupSortTypes
from
libs.es
import
ESPerform
from
trans2es.models.topic
import
CommunityCategoryTagRelation
from
trans2es.models.pictorial
import
PictorialTopics
from
trans2es.models.pictorial
import
CommunityPictorialActivity
from
alpha_types.venus
import
PICTORIAL_ACTIVITY_SORT
...
...
@@ -96,6 +97,10 @@ def pictorial_sort(user_id=-1, sort_type=GroupSortTypes.HOT_RECOMMEND, offset=0,
@bind
(
"physical/search/pictorial_topic"
)
def
pictorial_topic
(
topic_id
=-
1
,
offset
=
0
,
size
=
10
):
"""
帖子详情页的榜单推荐
先获取该帖子所属榜单 过滤下线的无帖子的被删除的榜单
再根据该帖子下的标签去获取有这些标签的榜单
最后根据该标签对应的分类标签去获取榜单
:remark 入选画报
:param user_id:
:param sort_type:
...
...
@@ -108,7 +113,7 @@ def pictorial_topic(topic_id=-1, offset=0, size=10):
# 获取es链接对象
es_cli_obj
=
ESPerform
.
get_cli
()
q
=
{}
# 获取帖子
从属的画报
# 获取帖子
及该帖子的标签
q
[
"query"
]
=
{
"bool"
:
{
"must"
:
[
...
...
@@ -144,25 +149,32 @@ def pictorial_topic(topic_id=-1, offset=0, size=10):
pict_pictorial_ids_list
=
item
[
"_source"
][
"pictorial_id"
]
topic_tag_list
=
item
[
"_source"
][
"tag_list"
]
logging
.
info
(
"get pict_pictorial_ids_list:
%
s"
%
pict_pictorial_ids_list
)
logging
.
info
(
"get topic_tag_list:
%
s"
%
topic_tag_list
)
##先拿到当前帖子对应的标签的分类ID
tag_type_ids
=
CommunityCategoryTagRelation
.
objects
.
filter
(
tag_id__in
=
topic_tag_list
,
is_online
=
True
,
is_deleted
=
False
)
.
values_list
(
"category_tag_id"
,
flat
=
True
)
logging
.
info
(
"get tag_type_ids:
%
s"
%
tag_type_ids
)
# 拿到所属榜单
if
len
(
pict_pictorial_ids_list
)
>
0
:
q
[
"query"
]
=
{
"bool"
:
{
"must"
:
[{
"terms"
:
{
"id"
:
pict_pictorial_ids_list
}
},
{
"term"
:
{
"is_online"
:
True
}
},
{
"term"
:
{
"is_deleted"
:
False
}
},
]
}
...
...
@@ -183,14 +195,20 @@ def pictorial_topic(topic_id=-1, offset=0, size=10):
pictorial_id
=
item
[
"_source"
][
"id"
]
pictorial_id_list
.
append
(
pictorial_id
)
if
len
(
pictorial_id_list
)
<
10
:
functions_list
=
[]
logging
.
info
(
"get pictorial_id_list:
%
s"
%
pictorial_id_list
)
all_tag
=
[]
all_tag
.
extend
(
topic_tag_list
)
all_tag
.
extend
(
tag_type_ids
)
logging
.
info
(
"get all_tag:
%
s"
%
all_tag
)
# 如果不够10个去拿所属标签的榜单和所属分类的标签的榜单
if
len
(
pictorial_id_list
)
<
10
and
len
(
all_tag
)
>
0
:
num
=
10
-
len
(
pictorial_id_list
)
query
=
{
"query"
:
{
"bool"
:
{
"must"
:
[{
"terms"
:
{
"tag_id"
:
topic_tag_list
"tag_id"
:
all_tag
}},
{
"term"
:
{
"is_online"
:
True
...
...
@@ -209,19 +227,18 @@ def pictorial_topic(topic_id=-1, offset=0, size=10):
}]
}
}
}
functions_list
=
[]
functions_list
.
append
({
"filter"
:
{
"constant_score"
:
{
"filter"
:
{
"term"
:
{
"term
s
"
:
{
"tag_id"
:
topic_tag_list
}
}
}
},
"weight"
:
20
"weight"
:
20
0
})
q
=
{
"query"
:
{
...
...
@@ -248,17 +265,17 @@ def pictorial_topic(topic_id=-1, offset=0, size=10):
}
}
]
q
[
"from"
]
=
0
q
[
"size"
]
=
10
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"pictorial"
,
q
,
offset
,
size
)
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"pictorial"
,
q
,
0
,
10
)
logging
.
info
(
"get result_dict:
%
s"
%
result_dict
)
if
len
(
result_dict
[
"hits"
])
>
0
:
for
item
in
result_dict
[
"hits"
]:
id
=
item
[
"_source"
][
"id"
]
if
id
not
in
pictorial_id_list
:
pictorial_id_list
.
append
(
id
)
#
logging
.
info
(
"get pictorial_id_list:
%
s"
%
pictorial_id_list
)
pictorial_list
=
pictorial_id_list
if
len
(
pictorial_id_list
)
<
10
else
pictorial_id_list
[:
10
]
return
{
"pictorial_ids_list"
:
pictorial_list
}
...
...
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