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
3d8b104e
Commit
3d8b104e
authored
Jan 29, 2019
by
zhanglu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
帖子搜索
parent
a15b85c7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
2 deletions
+101
-2
topic.py
search/utils/topic.py
+89
-2
topic.py
search/views/topic.py
+12
-0
No files found.
search/utils/topic.py
View file @
3d8b104e
...
...
@@ -4,6 +4,9 @@
import
logging
import
traceback
import
json
from
alpha_types.venus
import
TOPIC_SEARCH_SORT
from
libs.es
import
ESPerform
from
.common
import
TopicDocumentField
from
search.utils.common
import
*
...
...
@@ -464,4 +467,89 @@ class TopicUtils(object):
return
result_dict
[
"hits"
]
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
list
()
\ No newline at end of file
return
list
()
@classmethod
def
process_filters
(
cls
,
filters
):
"""处理过滤器部分。"""
f
=
[
{
"term"
:
{
"is_online"
:
True
}},
{
"term"
:
{
"is_deleted"
:
False
}},
]
if
not
filters
:
return
f
for
k
,
v
in
filters
.
items
():
if
k
==
"group_id"
:
f
.
append
({
"term"
:
{
"group_id"
:
v
},
})
return
f
@classmethod
def
process_nfilters
(
cls
,
nfilters
):
"""处理过滤器部分。"""
nf
=
[]
if
not
nfilters
:
return
nf
for
k
,
v
in
nfilters
.
items
():
pass
return
nf
@classmethod
def
process_sort
(
cls
,
sorts_by
):
"""处理排序部分。"""
sort_rule
=
[]
for
sort
in
sorts_by
:
if
sort
==
TOPIC_SEARCH_SORT
.
VOTE_NUM
:
sort_rule
.
append
({
"vote_num"
:{
"order"
:
"desc"
}
})
return
sort_rule
@classmethod
def
list_topic_ids
(
cls
,
filters
,
nfilters
,
sorts_by
,
offset
=
0
,
size
=
10
):
q
=
{
"query"
:
{
"filtered"
:
{
"query"
:
{
"match_all"
:{}},
}
},
"_source"
:
{
"includes"
:[
"id"
]
},
"sort"
:
[],
}
if
filters
or
nfilters
:
f
=
cls
.
process_filters
(
filters
)
nf
=
cls
.
process_nfilters
(
nfilters
)
q
[
"query"
][
"filtered"
][
"filter"
]
=
{
"bool"
:
{
"must"
:
f
,
"must_not"
:
nf
,
}
}
if
sorts_by
:
sorts
=
cls
.
process_sort
(
sorts_by
)
q
[
"sort"
]
=
sorts
try
:
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
"topic"
,
query_body
=
q
,
offset
=
offset
,
size
=
size
)
return
result_dict
[
"hits"
]
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
search/views/topic.py
View file @
3d8b104e
...
...
@@ -254,3 +254,15 @@ def query_topic_by_tag_aggregation(user_id,tag_id, offset, size):
return
{
"recommend_topic_id"
:
[]}
@bind
(
"physical/search/topic"
)
def
topic_search
(
filters
,
nfilters
=
None
,
sorts_by
=
None
,
offset
=
0
,
size
=
10
):
"""帖子搜索。"""
try
:
result_list
=
TopicUtils
.
list_topic_ids
(
filters
=
filters
,
nfilters
=
nfilters
,
sorts_by
=
sorts_by
,
offset
=
offset
,
size
=
size
)
topic_ids
=
[
item
[
"_source"
][
"id"
]
for
item
in
result_list
]
return
{
"topic_ids"
:
topic_ids
}
except
:
logging
.
error
(
"catch exception, err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"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