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
0725fb40
Commit
0725fb40
authored
Mar 21, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add
parent
65916c36
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
18 deletions
+79
-18
group.py
search/views/group.py
+63
-17
pictorial.json
trans2es/mapping/pictorial.json
+3
-1
pictorial.py
trans2es/models/pictorial.py
+12
-0
pictorial_transfer.py
trans2es/utils/pictorial_transfer.py
+1
-0
No files found.
search/views/group.py
View file @
0725fb40
...
...
@@ -13,7 +13,7 @@ from libs.es import ESPerform
@bind
(
"physical/search/query_pictorial"
)
def
query_group
(
query
=
""
,
offset
=
0
,
size
=
10
):
def
query_group
(
query
=
""
,
offset
=
0
,
size
=
10
):
"""
:remark:小组搜索排序策略,缺少排序策略
:param query:
...
...
@@ -22,7 +22,7 @@ def query_group(query="",offset=0,size=10):
:return:
"""
try
:
result_dict
=
GroupUtils
.
get_group_query_result
(
query
,
offset
,
size
)
result_dict
=
GroupUtils
.
get_group_query_result
(
query
,
offset
,
size
)
group_ids_list
=
[]
if
len
(
result_dict
[
"hits"
])
>
0
:
...
...
@@ -31,10 +31,11 @@ def query_group(query="",offset=0,size=10):
return
{
"group_ids"
:
group_ids_list
}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"group_ids"
:[]}
return
{
"group_ids"
:
[]}
@bind
(
"physical/search/pictorial_sort"
)
def
pictorial_sort
(
user_id
=-
1
,
sort_type
=
GroupSortTypes
.
HOT_RECOMMEND
,
offset
=
0
,
size
=
10
):
def
pictorial_sort
(
user_id
=-
1
,
sort_type
=
GroupSortTypes
.
HOT_RECOMMEND
,
offset
=
0
,
size
=
10
):
"""
:remark 小组排序,缺少:前1天发评论人数*x
:param user_id:
...
...
@@ -44,34 +45,79 @@ def pictorial_sort(user_id=-1,sort_type=GroupSortTypes.HOT_RECOMMEND,offset=0,si
:return:
"""
try
:
if
not
isinstance
(
user_id
,
int
):
if
not
isinstance
(
user_id
,
int
):
user_id
=
-
1
#获取es链接对象
#
获取es链接对象
es_cli_obj
=
ESPerform
.
get_cli
()
if
sort_type
==
GroupSortTypes
.
HOT_RECOMMEND
:
pictorial_ids_list
=
GroupUtils
.
get_hot_pictorial_recommend_result_list
(
offset
,
size
,
es_cli_obj
)
if
sort_type
==
GroupSortTypes
.
HOT_RECOMMEND
:
pictorial_ids_list
=
GroupUtils
.
get_hot_pictorial_recommend_result_list
(
offset
,
size
,
es_cli_obj
)
return
{
"pictorial_recommend_ids"
:
pictorial_ids_list
}
return
{
"pictorial_recommend_ids"
:
pictorial_ids_list
}
elif
sort_type
==
GroupSortTypes
.
ATTENTION_RECOMMEND
:
attention_pictorial_list
=
GroupUtils
.
get_user_attention_pictorial_list
(
user_id
,
offset
=
0
,
size
=
1
,
es_cli_obj
=
es_cli_obj
)
if
len
(
attention_pictorial_list
)
==
0
:
elif
sort_type
==
GroupSortTypes
.
ATTENTION_RECOMMEND
:
attention_pictorial_list
=
GroupUtils
.
get_user_attention_pictorial_list
(
user_id
,
offset
=
0
,
size
=
1
,
es_cli_obj
=
es_cli_obj
)
if
len
(
attention_pictorial_list
)
==
0
:
return
{
"pictorial_recommend_ids"
:
[]}
else
:
attention_pictorial_id_list
=
[
item
[
"pictorial_id"
]
for
item
in
attention_pictorial_list
]
sorted_pictorial_ids_list
=
GroupUtils
.
get_pictorial_ids_by_aggs
(
attention_pictorial_id_list
,
es_cli_obj
)
sorted_pictorial_ids_list
=
GroupUtils
.
get_pictorial_ids_by_aggs
(
attention_pictorial_id_list
,
es_cli_obj
)
pictorial_recommend_ids_list
=
sorted_pictorial_ids_list
#if len(group_recommend_ids_list) < size and len(group_recommend_ids_list)<len(attention_group_list):
sorted_attention_pictorial_list
=
sorted
(
attention_pictorial_list
,
key
=
lambda
item
:
item
[
"update_time_val"
],
reverse
=
True
)
# if len(group_recommend_ids_list) < size and len(group_recommend_ids_list)<len(attention_group_list):
sorted_attention_pictorial_list
=
sorted
(
attention_pictorial_list
,
key
=
lambda
item
:
item
[
"update_time_val"
],
reverse
=
True
)
for
item
in
sorted_attention_pictorial_list
:
if
item
[
"pictorial_id"
]
not
in
pictorial_recommend_ids_list
:
pictorial_recommend_ids_list
.
append
(
item
[
"pictorial_id"
])
return
{
"pictorial_recommend_ids"
:
pictorial_recommend_ids_list
[
offset
:(
offset
+
size
)]}
return
{
"pictorial_recommend_ids"
:
pictorial_recommend_ids_list
[
offset
:(
offset
+
size
)]}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"pictorial_recommend_ids"
:
[]}
@bind
(
"physical/search/pictorial_topic"
)
def
pictorial_topic
(
topic_id
=-
1
,
offset
=
0
,
size
=
10
):
"""
:remark 小组排序,缺少:前1天发评论人数*x
:param user_id:
:param sort_type:
:param offset:
:param size:
:return:
"""
try
:
if
not
isinstance
(
topic_id
,
int
):
user_id
=
-
1
# 获取es链接对象
es_cli_obj
=
ESPerform
.
get_cli
()
q
=
{}
# 获取帖子从属的画报
q
[
"query"
]
=
{
"term"
:
{
"id"
:
topic_id
}
}
q
[
"_source"
]
=
{
"include"
:
[
"id"
,
"pictorial_id"
]
}
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"topic"
,
q
,
offset
,
size
)
pictorial_ids_list
=
[]
if
len
(
result_dict
[
"hits"
])
>
0
:
pictorial_ids_list
=
[
item
[
"_source"
][
"id"
]
for
item
in
result_dict
[
"hits"
]]
#
# if len(pictorial_ids_list) <10:
return
{
"pictorial_ids_list"
:[]}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"pictorial_
recommend_ids"
:
[]}
return
{
"pictorial_
ids_list"
:
[]}
trans2es/mapping/pictorial.json
View file @
0725fb40
...
...
@@ -14,7 +14,8 @@
"create_time"
:{
"type"
:
"date"
,
"format"
:
"date_time_no_millis"
},
"update_time"
:{
"type"
:
"date"
,
"format"
:
"date_time_no_millis"
},
"tag_id"
:{
"type"
:
"long"
},
"tag_name"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"gm_default_index"
}
"tag_name"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"gm_default_index"
},
"topic_id_list"
:{
"type"
:
"long"
}
}
}
\ No newline at end of file
trans2es/models/pictorial.py
View file @
0725fb40
...
...
@@ -60,6 +60,18 @@ class Pictorial(models.Model):
icon
=
models
.
CharField
(
verbose_name
=
u'画报名称'
,
max_length
=
255
)
topic_num
=
models
.
IntegerField
(
verbose_name
=
u'次数'
)
def
get_topic_id
(
self
):
try
:
topic_id
=
[]
topic_id_list
=
PictorialTopics
.
objects
.
filter
(
pictorial_id
=
self
.
id
)
.
values_list
(
"topic_id"
,
flat
=
True
)
for
i
in
topic_id_list
:
topic_id
.
append
(
i
)
return
topic_id
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
False
# 获取前一天4,5星发帖数
def
get_high_quality_topic_num
(
self
):
try
:
...
...
trans2es/utils/pictorial_transfer.py
View file @
0725fb40
...
...
@@ -36,6 +36,7 @@ class PictorialTransfer(object):
tag_id
=
instance
.
get_tag_by_id
()
res
[
"tag_id"
]
=
tag_id
res
[
"tag_name"
]
=
instance
.
get_tag_by_name
(
tag_id
)
res
[
"topic_id_list"
]
=
instance
.
get_topic_id
()
return
res
except
:
...
...
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