Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
search_tips
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
rank
search_tips
Commits
e448f56f
Commit
e448f56f
authored
Jun 10, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add
parent
a955f0d8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
1 deletion
+55
-1
words_utils.py
trans2es/commons/words_utils.py
+55
-1
No files found.
trans2es/commons/words_utils.py
View file @
e448f56f
# coding=utf8
# coding=utf8
from
__future__
import
unicode_literals
,
absolute_import
,
print_function
from
__future__
import
unicode_literals
,
absolute_import
,
print_function
from
libs.es
import
ESPerform
import
logging
import
logging
import
traceback
import
traceback
import
json
import
json
from
django.conf
import
settings
from
libs.cache
import
redis_client
from
libs.cache
import
redis_client
from
trans2es.models.query_word_conversion
import
TagConversion
,
DoctorConversion
,
HospitalConversion
from
trans2es.models.query_word_conversion
import
TagConversion
,
DoctorConversion
,
HospitalConversion
...
@@ -204,3 +205,56 @@ def get_tips_word_type(query=''):
...
@@ -204,3 +205,56 @@ def get_tips_word_type(query=''):
labels
.
sort
(
key
=
label_key
,
reverse
=
True
)
labels
.
sort
(
key
=
label_key
,
reverse
=
True
)
return
labels
[
0
]
return
labels
[
0
]
def
label_key
(
label
):
return
LABEL_VALUE
.
get
(
label
)
def
get_tips_word_type
(
query
=
''
):
try
:
labels
=
list
()
query_base64
=
base64
.
b64encode
(
query
.
encode
(
'utf8'
))
.
decode
(
'utf8'
)
key
=
QUERY_KEY
.
format
(
query_base64
)
logging
.
info
(
"get key:
%
s"
%
key
)
labels
=
list
(
map
(
lambda
x
:
x
.
decode
(
"utf8"
),
list
(
redis_client
.
smembers
(
key
))))
logging
.
info
(
"get labels:
%
s"
%
labels
)
if
len
(
labels
)
==
0
:
labels
=
list
(
get_synonym_query
(
query
))
labels
.
append
(
MIND_TYPE
.
UNKNOWN
)
if
query
in
QUERY_WORD_LABEL_NEED_MODIFIED
:
labels
.
append
(
MIND_TYPE
.
PROJECT
)
labels
.
sort
(
key
=
label_key
,
reverse
=
True
)
return
{
'label'
:
labels
[
0
]}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
'label'
:
MIND_TYPE
.
UNKNOWN
}
def
get_synonym_query
(
query
=
''
):
try
:
synonym_term_set
=
set
()
synonym_term_set_labels
=
set
()
body
=
{
'text'
:
query
,
'analyzer'
:
"gm_default_index"
}
res
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(
settings
.
GM_ORI_ES_INFO_LIST
),
sub_index_name
=
"newwiki"
,
doc_type
=
"newwiki"
,
query_body
=
body
)
logging
.
info
(
"get res:
%
s"
%
res
)
for
item
in
res
[
"tokens"
]:
if
item
[
"type"
]
==
"SYNONYM"
:
synonym_term_set
.
add
(
item
[
"token"
])
for
query
in
synonym_term_set
:
query_base64
=
base64
.
b64encode
(
query
.
encode
(
'utf8'
))
.
decode
(
'utf8'
)
key
=
QUERY_KEY
.
format
(
query_base64
)
labels
=
list
(
map
(
lambda
x
:
x
.
decode
(
"utf8"
),
list
(
redis_client
.
smembers
(
key
))))
logging
.
info
(
"get labels synonym:
%
s"
%
labels
)
for
i
in
labels
:
synonym_term_set_labels
.
add
(
i
)
return
synonym_term_set_labels
except
:
logging
.
error
(
"catch exception, query_sku:
%
s"
%
traceback
.
format_exc
())
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