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
吴升宇
physical
Commits
d7f0179c
Commit
d7f0179c
authored
Aug 07, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Plain Diff
add
parents
da333ae5
f1b5ab39
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
36 deletions
+69
-36
es.py
libs/es.py
+27
-16
topic.py
search/utils/topic.py
+27
-17
topic.py
search/views/topic.py
+15
-3
No files found.
libs/es.py
View file @
d7f0179c
...
@@ -155,9 +155,9 @@ class ESPerform(object):
...
@@ -155,9 +155,9 @@ class ESPerform(object):
bulk_actions
=
[]
bulk_actions
=
[]
if
sub_index_name
==
"topic"
or
\
if
sub_index_name
==
"topic"
or
\
sub_index_name
==
"topic-star-routing"
or
\
sub_index_name
==
"topic-star-routing"
or
\
sub_index_name
==
"topic-high-star"
:
sub_index_name
==
"topic-high-star"
:
for
data
in
data_list
:
for
data
in
data_list
:
if
data
:
if
data
:
bulk_actions
.
append
({
bulk_actions
.
append
({
...
@@ -232,7 +232,7 @@ class ESPerform(object):
...
@@ -232,7 +232,7 @@ class ESPerform(object):
return
{
"total_count"
:
0
,
"hits"
:
[]}
return
{
"total_count"
:
0
,
"hits"
:
[]}
@classmethod
@classmethod
def
get_analyze_results
(
cls
,
es_cli
,
sub_index_name
,
query_body
):
def
get_analyze_results
(
cls
,
es_cli
,
sub_index_name
,
query_body
):
try
:
try
:
assert
(
es_cli
is
not
None
)
assert
(
es_cli
is
not
None
)
...
@@ -242,7 +242,7 @@ class ESPerform(object):
...
@@ -242,7 +242,7 @@ class ESPerform(object):
logging
.
error
(
"index:
%
s is not existing,get_search_results error!"
%
official_index_name
)
logging
.
error
(
"index:
%
s is not existing,get_search_results error!"
%
official_index_name
)
return
None
return
None
res
=
es_cli
.
indices
.
analyze
(
index
=
official_index_name
,
body
=
query_body
)
res
=
es_cli
.
indices
.
analyze
(
index
=
official_index_name
,
body
=
query_body
)
return
res
return
res
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
@@ -276,7 +276,7 @@ class ESPerform(object):
...
@@ -276,7 +276,7 @@ class ESPerform(object):
if
high_num
>
3
:
if
high_num
>
3
:
logging
.
info
(
"check es_nodes_load high,cpu load:
%
s,ori_cpu_info:
%
s"
%
(
logging
.
info
(
"check es_nodes_load high,cpu load:
%
s,ori_cpu_info:
%
s"
%
(
str
(
es_nodes_list
),
str
(
es_nodes_info_list
)))
str
(
es_nodes_list
),
str
(
es_nodes_info_list
)))
return
True
return
True
else
:
else
:
return
False
return
False
...
@@ -298,8 +298,8 @@ class ESPerform(object):
...
@@ -298,8 +298,8 @@ class ESPerform(object):
functions_list
+=
[
functions_list
+=
[
{
{
"filter"
:
{
"filter"
:
{
"constant_score"
:{
"constant_score"
:
{
"filter"
:{
"filter"
:
{
"term"
:
{
"content_level"
:
6
}}
"term"
:
{
"content_level"
:
6
}}
}
}
},
},
...
@@ -307,8 +307,8 @@ class ESPerform(object):
...
@@ -307,8 +307,8 @@ class ESPerform(object):
},
},
{
{
"filter"
:
{
"filter"
:
{
"constant_score"
:{
"constant_score"
:
{
"filter"
:{
"filter"
:
{
"term"
:
{
"content_level"
:
5
}}
"term"
:
{
"content_level"
:
5
}}
}
}
},
},
...
@@ -316,8 +316,8 @@ class ESPerform(object):
...
@@ -316,8 +316,8 @@ class ESPerform(object):
},
},
{
{
"filter"
:
{
"filter"
:
{
"constant_score"
:{
"constant_score"
:
{
"filter"
:{
"filter"
:
{
"term"
:
{
"content_level"
:
4
}}
"term"
:
{
"content_level"
:
4
}}
}
}
},
},
...
@@ -411,7 +411,7 @@ class ESPerform(object):
...
@@ -411,7 +411,7 @@ class ESPerform(object):
}
}
},
},
"_source"
:
{
"_source"
:
{
"include"
:
[
"id"
,
"user_id"
]
"include"
:
[
"id"
,
"user_id"
]
},
},
"sort"
:
[
"sort"
:
[
{
"latest_reply_time"
:
{
"order"
:
"desc"
}},
{
"latest_reply_time"
:
{
"order"
:
"desc"
}},
...
@@ -420,7 +420,7 @@ class ESPerform(object):
...
@@ -420,7 +420,7 @@ class ESPerform(object):
],
],
"collapse"
:
{
"collapse"
:
{
"field"
:
"user_id"
"field"
:
"user_id"
}
}
}
}
if
len
(
have_read_topic_id_list
)
>
0
:
if
len
(
have_read_topic_id_list
)
>
0
:
...
@@ -429,7 +429,8 @@ class ESPerform(object):
...
@@ -429,7 +429,8 @@ class ESPerform(object):
"id"
:
have_read_topic_id_list
"id"
:
have_read_topic_id_list
}
}
}
}
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
"topic-high-star"
,
query_body
=
q
,
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
"topic-high-star"
,
query_body
=
q
,
offset
=
0
,
size
=
size
,
routing
=
"6"
)
offset
=
0
,
size
=
size
,
routing
=
"6"
)
topic_id_list
=
[
item
[
"_source"
][
"id"
]
for
item
in
result_dict
[
"hits"
]]
topic_id_list
=
[
item
[
"_source"
][
"id"
]
for
item
in
result_dict
[
"hits"
]]
...
@@ -441,7 +442,17 @@ class ESPerform(object):
...
@@ -441,7 +442,17 @@ class ESPerform(object):
logging
.
info
(
"topic_id_list:
%
s"
%
str
(
topic_id_dict
))
logging
.
info
(
"topic_id_list:
%
s"
%
str
(
topic_id_dict
))
return
topic_id_list
,
topic_id_dict
return
topic_id_list
,
topic_id_dict
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
list
()
return
list
()
@classmethod
def
get_highlight
(
cls
,
fields
=
[]):
field_highlight
=
{
'fields'
:
{
k
:
{}
for
k
in
fields
},
'pre_tags'
:
[
'<
%
s>'
%
'ems'
],
'post_tags'
:
[
'</
%
s>'
%
'ems'
]
}
return
field_highlight
search/utils/topic.py
View file @
d7f0179c
...
@@ -159,6 +159,9 @@ class TopicUtils(object):
...
@@ -159,6 +159,9 @@ class TopicUtils(object):
user_tag_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"tag_list"
]
user_tag_list
=
result_dict
[
"hits"
][
0
][
"_source"
][
"tag_list"
]
q
=
dict
()
q
=
dict
()
topic_id_list
=
list
()
q
[
"query"
]
=
dict
()
q
[
"query"
]
=
dict
()
functions_list
=
[
functions_list
=
[
...
@@ -261,7 +264,7 @@ class TopicUtils(object):
...
@@ -261,7 +264,7 @@ class TopicUtils(object):
{
"term"
:
{
"content_level"
:
6
}}
{
"term"
:
{
"content_level"
:
6
}}
)
)
q
[
"_source"
]
=
{
q
[
"_source"
]
=
{
"includes"
:
[
"id"
]
"includes"
:
[
"id"
,
"highlight"
,
"description"
]
}
}
if
query
is
None
:
if
query
is
None
:
...
@@ -319,6 +322,13 @@ class TopicUtils(object):
...
@@ -319,6 +322,13 @@ class TopicUtils(object):
}
}
}
}
]
]
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
index_type
,
query_body
=
q
,
offset
=
offset
,
size
=
size
,
routing
=
routing
)
for
item
in
result_dict
[
"hits"
]:
topic_id_list
.
append
(
item
[
"_source"
][
"id"
])
else
:
else
:
multi_match
=
{
multi_match
=
{
'query'
:
query
,
'query'
:
query
,
...
@@ -329,9 +339,9 @@ class TopicUtils(object):
...
@@ -329,9 +339,9 @@ class TopicUtils(object):
functions_list
+=
[
functions_list
+=
[
{
{
"weight"
:
400
,
"weight"
:
400
,
"filter"
:{
"filter"
:
{
"constant_score"
:{
"constant_score"
:
{
"filter"
:{
"filter"
:
{
"term"
:
{
"user_nick_name_pre"
:
query
.
lower
()}
"term"
:
{
"user_nick_name_pre"
:
query
.
lower
()}
}
}
}
}
...
@@ -340,15 +350,15 @@ class TopicUtils(object):
...
@@ -340,15 +350,15 @@ class TopicUtils(object):
{
{
"weight"
:
400
,
"weight"
:
400
,
"filter"
:
{
"filter"
:
{
"constant_score"
:{
"constant_score"
:
{
"filter"
:{
"filter"
:
{
"bool"
:
{
"bool"
:
{
"must"
:
{
"must"
:
{
"term"
:
{
"content_level"
:
6
},
"term"
:
{
"content_level"
:
6
},
},
},
"minimum_should_match"
:
1
,
"minimum_should_match"
:
1
,
"should"
:
[
"should"
:
[
{
'match_phrase'
:
{
"content"
:
query
}},
{
'match_phrase'
:
{
"content"
:
query
}},
{
'match_phrase'
:
{
"tag_name_list"
:
query
}},
{
'match_phrase'
:
{
"tag_name_list"
:
query
}},
# {'multi_match': multi_match},
# {'multi_match': multi_match},
{
"term"
:
{
"tag_list"
:
tag_id
}},
{
"term"
:
{
"tag_list"
:
tag_id
}},
...
@@ -362,8 +372,8 @@ class TopicUtils(object):
...
@@ -362,8 +372,8 @@ class TopicUtils(object):
{
{
"weight"
:
400
,
"weight"
:
400
,
"filter"
:
{
"filter"
:
{
"constant_score"
:{
"constant_score"
:
{
"filter"
:{
"filter"
:
{
"bool"
:
{
"bool"
:
{
"must"
:
{
"must"
:
{
"term"
:
{
"content_level"
:
5
},
"term"
:
{
"content_level"
:
5
},
...
@@ -384,8 +394,8 @@ class TopicUtils(object):
...
@@ -384,8 +394,8 @@ class TopicUtils(object):
{
{
"weight"
:
400
,
"weight"
:
400
,
"filter"
:
{
"filter"
:
{
"constant_score"
:{
"constant_score"
:
{
"filter"
:{
"filter"
:
{
"bool"
:
{
"bool"
:
{
"must"
:
{
"must"
:
{
"term"
:
{
"content_level"
:
4
},
"term"
:
{
"content_level"
:
4
},
...
@@ -425,7 +435,7 @@ class TopicUtils(object):
...
@@ -425,7 +435,7 @@ class TopicUtils(object):
}
}
},
},
{
{
"latest_reply_time"
:{
"latest_reply_time"
:
{
"order"
:
"desc"
"order"
:
"desc"
}
}
},
},
...
@@ -435,14 +445,14 @@ class TopicUtils(object):
...
@@ -435,14 +445,14 @@ class TopicUtils(object):
}
}
}
}
]
]
q
[
"highlight"
]
=
ESPerform
.
get_highlight
([
"content"
])
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
index_type
,
query_body
=
q
,
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
index_type
,
query_body
=
q
,
offset
=
offset
,
size
=
size
,
routing
=
routing
)
offset
=
offset
,
size
=
size
,
routing
=
routing
)
topic_id_list
=
list
()
for
item
in
result_dict
[
"hits"
]:
topic_id_list
.
append
({
"id"
:
item
[
"_source"
][
"id"
],
"highlight"
:
item
[
"highlight"
]})
for
item
in
result_dict
[
"hits"
]:
topic_id_list
.
append
(
item
[
"_source"
][
"id"
])
return
topic_id_list
return
topic_id_list
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
...
search/views/topic.py
View file @
d7f0179c
...
@@ -183,7 +183,12 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
...
@@ -183,7 +183,12 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
# topic_id_list.extend(recommend_topic_list[3:6])
# topic_id_list.extend(recommend_topic_list[3:6])
# else:
# else:
# topic_id_list.extend(rank_topic_id_list)
# topic_id_list.extend(rank_topic_id_list)
have_read_topic_id_list
.
extend
(
rank_topic_id_list
)
if
query
is
None
:
have_read_topic_id_list
.
extend
(
item
[
"id"
]
for
item
in
rank_topic_id_list
)
else
:
have_read_topic_id_list
.
extend
(
rank_topic_id_list
)
if
len
(
have_read_topic_id_list
)
>
30000
:
if
len
(
have_read_topic_id_list
)
>
30000
:
cut_len
=
len
(
have_read_topic_id_list
)
-
30000
cut_len
=
len
(
have_read_topic_id_list
)
-
30000
have_read_topic_id_list
=
have_read_topic_id_list
[
cut_len
:]
have_read_topic_id_list
=
have_read_topic_id_list
[
cut_len
:]
...
@@ -315,6 +320,8 @@ def home_query(device_id="", tag_id=-1, user_id=-1, query="", offset=0, size=10,
...
@@ -315,6 +320,8 @@ def home_query(device_id="", tag_id=-1, user_id=-1, query="", offset=0, size=10,
:return:
:return:
"""
"""
try
:
try
:
result_topic_data
=
list
()
if
not
user_id
:
if
not
user_id
:
user_id
=
-
1
user_id
=
-
1
if
not
isinstance
(
device_id
,
str
):
if
not
isinstance
(
device_id
,
str
):
...
@@ -326,10 +333,15 @@ def home_query(device_id="", tag_id=-1, user_id=-1, query="", offset=0, size=10,
...
@@ -326,10 +333,15 @@ def home_query(device_id="", tag_id=-1, user_id=-1, query="", offset=0, size=10,
recommend_topic_list
,
rank_topic_id_list
=
get_home_recommend_topic_ids
(
user_id
,
device_id
,
tag_id
,
recommend_topic_list
,
rank_topic_id_list
=
get_home_recommend_topic_ids
(
user_id
,
device_id
,
tag_id
,
offset
=
offset
,
size
=
size
,
offset
=
offset
,
size
=
size
,
query
=
query
,
disable_collpase
=
True
)
query
=
query
,
disable_collpase
=
True
)
result_topic_data
=
list
()
if
query_type
!=
3
and
rank_topic_id_list
:
if
query_type
!=
3
and
rank_topic_id_list
:
result_topic_data
.
append
()
for
item
in
rank_topic_id_list
:
result_topic_data
.
append
(
item
[
"id"
])
logging
.
info
(
"get result_topic_data:
%
s"
%
result_topic_data
)
return
{
"recommend_topic_ids"
:
result_topic_data
}
return
{
"recommend_topic_ids"
:
rank_topic_id_list
}
return
{
"recommend_topic_ids"
:
rank_topic_id_list
}
except
:
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