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
6191d68a
Commit
6191d68a
authored
Dec 28, 2018
by
段英荣
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' into 'master'
Dev See merge request
alpha/physical!67
parents
9e612ec9
b63d9b61
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
21 deletions
+80
-21
es.py
libs/es.py
+13
-9
tag.py
search/views/tag.py
+32
-8
tag.json
trans2es/mapping/tag.json
+18
-3
tag_transfer.py
trans2es/utils/tag_transfer.py
+17
-1
No files found.
libs/es.py
View file @
6191d68a
...
...
@@ -167,7 +167,7 @@ class ESPerform(object):
@classmethod
def
get_search_results
(
cls
,
es_cli
,
sub_index_name
,
query_body
,
offset
=
0
,
size
=
10
,
auto_create_index
=
False
,
doc_type
=
"_doc"
,
aggregations_query
=
False
):
auto_create_index
=
False
,
doc_type
=
"_doc"
,
aggregations_query
=
False
,
is_suggest_request
=
False
):
try
:
assert
(
es_cli
is
not
None
)
...
...
@@ -183,14 +183,17 @@ class ESPerform(object):
logging
.
info
(
"duan add,query_body:
%
s"
%
str
(
query_body
)
.
encode
(
"utf-8"
))
res
=
es_cli
.
search
(
index
=
official_index_name
,
doc_type
=
doc_type
,
body
=
query_body
,
from_
=
offset
,
size
=
size
)
result_dict
=
{
"total_count"
:
res
[
"hits"
][
"total"
],
"hits"
:
res
[
"hits"
][
"hits"
]
}
if
aggregations_query
:
result_dict
[
"aggregations"
]
=
res
[
"aggregations"
]
return
result_dict
if
is_suggest_request
:
return
res
else
:
result_dict
=
{
"total_count"
:
res
[
"hits"
][
"total"
],
"hits"
:
res
[
"hits"
][
"hits"
]
}
if
aggregations_query
:
result_dict
[
"aggregations"
]
=
res
[
"aggregations"
]
return
result_dict
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"total_count"
:
0
,
"hits"
:[]}
\ No newline at end of file
search/views/tag.py
View file @
6191d68a
...
...
@@ -24,6 +24,7 @@ def get_highlight(fields=[]):
@bind
(
"physical/search/query_tag"
)
def
query_tag
(
query
,
offset
,
size
):
try
:
"""
q = {
"query":{
"bool":{
...
...
@@ -48,17 +49,40 @@ def query_tag(query,offset,size):
"include": ["id", "name"]
}
}
q
[
"highlight"
]
=
get_highlight
([
"name"
])
q["highlight"] = get_highlight(["name"])
"""
q
=
{
"suggest"
:{
"tips-suggest"
:{
"prefix"
:
query
,
"completion"
:{
"field"
:
"suggest"
,
"contexts"
:{
"is_online"
:
[
True
],
"is_deleted"
:
[
False
]
}
}
}
},
"sort"
:
[
{
"near_new_topic_num"
:
{
"order"
:
"desc"
}}
],
"_source"
:
{
"include"
:
[
"id"
,
"name"
,
"is_deleted"
,
"is_online"
]
}
}
ret_list
=
list
()
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
"tag"
,
query_body
=
q
,
offset
=
offset
,
size
=
size
)
for
hit_item
in
result_dict
[
"hits"
]:
if
"name"
in
hit_item
[
"highlight"
]
and
len
(
hit_item
[
"highlight"
][
"name"
])
>
0
:
hit_item
[
"_source"
][
"highlight"
]
=
hit_item
[
"highlight"
][
"name"
][
0
]
else
:
hit_item
[
"_source"
][
"highlight"
]
=
""
ret_list
.
append
(
hit_item
[
"_source"
])
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
"tag"
,
query_body
=
q
,
offset
=
offset
,
size
=
size
,
is_suggest_request
=
True
)
for
tips_item
in
result_dict
[
"suggest"
][
"tips-suggest"
]:
for
hit_item
in
tips_item
[
"options"
]:
#if len(hit_item["contexts"])==2:
if
hit_item
[
"_source"
][
"is_deleted"
]
==
False
and
hit_item
[
"_source"
][
"is_online"
]
==
True
:
hitLight
=
u'<ems>
%
s</ems>'
%
query
hit_item
[
"_source"
][
"highlight"
]
=
hit_item
[
"_source"
][
"name"
]
.
replace
(
query
,
hitLight
)
ret_list
.
append
(
hit_item
[
"_source"
])
return
{
"tag_list"
:
ret_list
}
except
:
...
...
trans2es/mapping/tag.json
View file @
6191d68a
...
...
@@ -2,11 +2,25 @@
"dynamic"
:
"strict"
,
"properties"
:
{
"id"
:{
"type"
:
"long"
},
"suggest"
:{
"type"
:
"completion"
},
"suggest"
:{
"type"
:
"completion"
,
"contexts"
:[
{
"name"
:
"is_online"
,
"type"
:
"category"
,
"path"
:
"is_online"
},
{
"name"
:
"is_deleted"
,
"type"
:
"category"
,
"path"
:
"is_deleted"
}
]
},
"name"
:{
"type"
:
"text"
,
"analyzer"
:
"gm_default_index"
,
"search_analyzer"
:
"gm_default_index"
},
"tag_type"
:{
"type"
:
"long"
},
"is_online"
:{
"type"
:
"
boolean
"
},
//上线
"is_deleted"
:{
"type"
:
"
boolean
"
},
"is_online"
:{
"type"
:
"
keyword
"
},
//上线
"is_deleted"
:{
"type"
:
"
keyword
"
},
"near_new_topic_num"
:{
"type"
:
"long"
,
"store"
:
true
}
}
}
\ No newline at end of file
trans2es/utils/tag_transfer.py
View file @
6191d68a
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
,
absolute_import
,
print_function
import
os
import
sys
import
logging
...
...
@@ -17,7 +19,21 @@ class TagTransfer(object):
res
=
dict
()
res
[
"id"
]
=
instance
.
id
res
[
"suggest"
]
=
instance
.
name
tag_name_terms_list
=
list
()
for
i
in
range
(
len
(
instance
.
name
)):
for
j
in
range
(
i
,
len
(
instance
.
name
)
+
1
):
name_term
=
instance
.
name
[
i
:
j
]
.
strip
()
if
name_term
:
tag_name_terms_list
.
append
(
name_term
)
res
[
"suggest"
]
=
{
"input"
:
tag_name_terms_list
,
"contexts"
:{
"is_online"
:
[
instance
.
is_online
],
"is_deleted"
:
[
instance
.
is_deleted
]
}
}
res
[
"name"
]
=
instance
.
name
res
[
"is_online"
]
=
instance
.
is_online
res
[
"is_deleted"
]
=
instance
.
is_deleted
...
...
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