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
30991868
Commit
30991868
authored
Apr 09, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'test' into 'master'
Test See merge request
!228
parents
cad53f5b
099832ab
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
135 additions
and
42 deletions
+135
-42
Project.xml
.idea/codeStyles/Project.xml
+25
-0
group.py
search/utils/group.py
+109
-37
group.py
search/views/group.py
+1
-3
pictorial.json
trans2es/mapping/pictorial.json
+0
-2
No files found.
.idea/codeStyles/Project.xml
View file @
30991868
...
...
@@ -24,5 +24,29 @@
<option
name=
"ITERATION_ELEMENTS_WRAPPING"
value=
"chop_down_if_not_single"
/>
</formatting-settings>
</DBN-SQL>
<DBN-PSQL>
<case-options
enabled=
"false"
>
<option
name=
"KEYWORD_CASE"
value=
"lower"
/>
<option
name=
"FUNCTION_CASE"
value=
"lower"
/>
<option
name=
"PARAMETER_CASE"
value=
"lower"
/>
<option
name=
"DATATYPE_CASE"
value=
"lower"
/>
<option
name=
"OBJECT_CASE"
value=
"preserve"
/>
</case-options>
<formatting-settings
enabled=
"false"
/>
</DBN-PSQL>
<DBN-SQL>
<case-options
enabled=
"false"
>
<option
name=
"KEYWORD_CASE"
value=
"lower"
/>
<option
name=
"FUNCTION_CASE"
value=
"lower"
/>
<option
name=
"PARAMETER_CASE"
value=
"lower"
/>
<option
name=
"DATATYPE_CASE"
value=
"lower"
/>
<option
name=
"OBJECT_CASE"
value=
"preserve"
/>
</case-options>
<formatting-settings
enabled=
"false"
>
<option
name=
"STATEMENT_SPACING"
value=
"one_line"
/>
<option
name=
"CLAUSE_CHOP_DOWN"
value=
"chop_down_if_statement_long"
/>
<option
name=
"ITERATION_ELEMENTS_WRAPPING"
value=
"chop_down_if_not_single"
/>
</formatting-settings>
</DBN-SQL>
</code_scheme>
</component>
\ No newline at end of file
search/utils/group.py
View file @
30991868
...
...
@@ -9,7 +9,7 @@ from libs.es import ESPerform
class
GroupUtils
(
object
):
@classmethod
def
get_group_query_result
(
cls
,
query
,
offset
,
size
):
def
get_group_query_result
(
cls
,
query
,
offset
,
size
):
try
:
q
=
dict
()
...
...
@@ -38,49 +38,84 @@ class GroupUtils(object):
}
}
q
[
"_source"
]
=
{
"includes"
:[
"id"
]
"includes"
:
[
"id"
]
}
return
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
"group"
,
q
,
offset
,
size
)
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"total_count"
:
0
,
"hits"
:
[]}
return
{
"total_count"
:
0
,
"hits"
:
[]}
@classmethod
def
get_hot_pictorial_recommend_result_list
(
cls
,
offset
,
size
,
es_cli_obj
=
None
):
def
get_hot_pictorial_recommend_result_list
(
cls
,
offset
,
size
,
es_cli_obj
=
None
):
try
:
if
not
es_cli_obj
:
es_cli_obj
=
ESPerform
.
get_cli
()
q
=
dict
()
q
[
"query"
]
=
{
"bool"
:{
"must"
:[
"bool"
:
{
"must"
:
[
{
"term"
:
{
"is_online"
:
True
}},
{
"term"
:{
"is_deleted"
:
False
}}
{
"term"
:
{
"is_deleted"
:
False
}}
]
}
}
q
[
"sort"
]
=
[
{
"high_quality_topic_num"
:
{
"order"
:
"desc"
}}
{
"high_quality_topic_num"
:
{
"order"
:
"desc"
}}
]
q
[
"_source"
]
=
{
"includes"
:[
"id"
]
"includes"
:
[
"id"
]
}
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"pictorial"
,
q
,
offset
,
size
)
MAX_LOAD
=
1000
sizes
=
max
(
size
,
MAX_LOAD
)
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"pictorial"
,
q
,
offset
=
0
,
size
=
sizes
)
pictorial_ids_list
=
[]
if
len
(
result_dict
[
"hits"
])
>
0
:
pictorial_ids_list
=
[
item
[
"_source"
][
"id"
]
for
item
in
result_dict
[
"hits"
]]
return
pictorial_ids_list
pictorial_del_ids_list
=
[]
if
len
(
pictorial_ids_list
)
>
0
:
for
id
in
pictorial_ids_list
:
q
=
{
"query"
:
{
"bool"
:
{
"must"
:
[{
"term"
:
{
"pictorial_id"
:
id
}
},
{
"terms"
:
{
"content_level"
:
[
3
,
4
,
5
,
0
]
}
},
{
"term"
:
{
"is_online"
:
True
}
}]
}
}
}
topic_ids_list
=
[]
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"topic"
,
q
,
offset
=
0
,
size
=
sizes
)
if
len
(
result_dict
[
"hits"
])
>
0
:
topic_ids_list
=
[
item
[
"_source"
][
"id"
]
for
item
in
result_dict
[
"hits"
]]
if
len
(
topic_ids_list
)
>
5
:
pictorial_del_ids_list
.
append
(
id
)
return
pictorial_del_ids_list
[
offset
:(
offset
+
size
)]
else
:
return
[]
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
@classmethod
def
get_user_attention_pictorial_list
(
cls
,
user_id
,
offset
=
0
,
size
=
10
,
es_cli_obj
=
None
):
def
get_user_attention_pictorial_list
(
cls
,
user_id
,
offset
=
0
,
size
=
10
,
es_cli_obj
=
None
):
"""
:remark: 获取用户关注小组列表
:return:
...
...
@@ -91,29 +126,67 @@ class GroupUtils(object):
q
=
dict
()
q
[
"query"
]
=
{
"bool"
:{
"must"
:[
{
"term"
:{
"is_online"
:
True
}},
{
"term"
:
{
"user_id"
:
user_id
}},
{
"term"
:
{
"is_deleted"
:
False
}}
"bool"
:
{
"must"
:
[
{
"term"
:
{
"is_online"
:
True
}},
{
"term"
:
{
"user_id"
:
user_id
}},
{
"term"
:
{
"is_deleted"
:
False
}}
]
}
}
q
[
"_source"
]
=
{
"includes"
:[
"attention_pictorial_id_list"
]
"includes"
:
[
"attention_pictorial_id_list"
]
}
MAX_LOAD
=
1000
sizes
=
max
(
size
,
MAX_LOAD
)
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"user"
,
q
,
offset
=
0
,
size
=
sizes
)
pictorial_ids_list
=
[]
if
len
(
result_dict
[
"hits"
])
>
0
:
pictorial_ids_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"attention_pictorial_id_list"
]
pictorial_del_ids_list
=
[]
if
len
(
pictorial_ids_list
)
>
0
:
for
id
in
pictorial_ids_list
:
q
=
{
"query"
:
{
"bool"
:
{
"must"
:
[{
"term"
:
{
"pictorial_id"
:
id
}
},
{
"terms"
:
{
"content_level"
:
[
3
,
4
,
5
,
0
]
}
},
{
"term"
:
{
"is_online"
:
True
}
}]
}
}
}
topic_ids_list
=
[]
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"topic"
,
q
,
offset
=
0
,
size
=
sizes
)
if
len
(
result_dict
[
"hits"
])
>
0
:
topic_ids_list
=
[
item
[
"_source"
][
"id"
]
for
item
in
result_dict
[
"hits"
]]
if
len
(
topic_ids_list
)
>
5
:
pictorial_del_ids_list
.
append
(
id
)
return
pictorial_del_ids_list
[
offset
:(
offset
+
size
)]
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"user"
,
q
,
offset
,
size
)
if
len
(
result_dict
[
"hits"
])
>
0
:
return
result_dict
[
"hits"
][
0
][
"_source"
][
"attention_pictorial_id_list"
]
else
:
return
[]
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
@classmethod
def
get_pictorial_ids_by_aggs
(
cls
,
pictorial_ids_list
,
es_cli_obj
=
None
):
def
get_pictorial_ids_by_aggs
(
cls
,
pictorial_ids_list
,
es_cli_obj
=
None
):
"""
:remark:聚合查询获取小组列表
:param group_id_list:
...
...
@@ -124,34 +197,34 @@ class GroupUtils(object):
es_cli_obj
=
ESPerform
.
get_cli
()
q
=
dict
()
q
[
"size"
]
=
0
q
[
"size"
]
=
0
q
[
"query"
]
=
{
"terms"
:{
"pictorial_id"
:
pictorial_ids_list
"terms"
:
{
"pictorial_id"
:
pictorial_ids_list
}
}
q
[
"aggs"
]
=
{
"pictorial_ids"
:{
"terms"
:{
"field"
:
"pictorial_id"
"pictorial_ids"
:
{
"terms"
:
{
"field"
:
"pictorial_id"
},
"aggs"
:{
"max_date"
:{
"max"
:{
"field"
:
"update_time_val"
"aggs"
:
{
"max_date"
:
{
"max"
:
{
"field"
:
"update_time_val"
}
}
}
}
}
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"topic"
,
q
,
aggregations_query
=
True
)
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"topic"
,
q
,
aggregations_query
=
True
)
buckets_list
=
result_dict
[
"aggregations"
][
"pictorial_ids"
][
"buckets"
]
sorted_buckets_list
=
sorted
(
buckets_list
,
key
=
lambda
item
:
item
[
"max_date"
][
"value"
],
reverse
=
True
)
sorted_buckets_list
=
sorted
(
buckets_list
,
key
=
lambda
item
:
item
[
"max_date"
][
"value"
],
reverse
=
True
)
sorted_pictorial_id_list
=
[
item
[
"key"
]
for
item
in
sorted_buckets_list
]
return
sorted_pictorial_id_list
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
\ No newline at end of file
return
[]
search/views/group.py
View file @
30991868
...
...
@@ -53,7 +53,6 @@ def pictorial_sort(user_id=-1, sort_type=GroupSortTypes.HOT_RECOMMEND, offset=0,
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
}
elif
sort_type
==
GroupSortTypes
.
ATTENTION_RECOMMEND
:
...
...
@@ -61,6 +60,7 @@ def pictorial_sort(user_id=-1, sort_type=GroupSortTypes.HOT_RECOMMEND, offset=0,
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
,
...
...
@@ -73,7 +73,6 @@ def pictorial_sort(user_id=-1, sort_type=GroupSortTypes.HOT_RECOMMEND, offset=0,
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
)]}
except
:
...
...
@@ -106,7 +105,6 @@ def pictorial_topic(topic_id=-1, offset=0, size=10):
"includes"
:
[
"id"
,
"pictorial_id"
,
"tag_list"
]
}
result_dict
=
ESPerform
.
get_search_results
(
es_cli_obj
,
"topic"
,
q
,
offset
,
size
)
logging
.
info
(
"get result_dict:
%
s"
%
result_dict
)
pict_pictorial_ids_list
=
[]
topic_tag_list
=
[]
pictorial_id_list
=
[]
...
...
trans2es/mapping/pictorial.json
View file @
30991868
...
...
@@ -16,6 +16,5 @@
"tag_id"
:{
"type"
:
"long"
},
"tag_name"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"gm_default_index"
},
"topic_id_list"
:{
"type"
:
"long"
}
}
}
\ No newline at end of file
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