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
1faad256
Commit
1faad256
authored
Feb 17, 2020
by
lixiaofang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add
parent
2de1926e
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
110 additions
and
15 deletions
+110
-15
words_utils.py
trans2es/commons/words_utils.py
+45
-3
trans2es_mapping2es.py
trans2es/management/commands/trans2es_mapping2es.py
+4
-1
suggest-v2.json
trans2es/mapping/suggest-v2.json
+25
-0
suggest-v3.json
trans2es/mapping/suggest-v3.json
+25
-0
doctor_transfer.py
trans2es/utils/doctor_transfer.py
+0
-1
search_query.py
trans2es/utils/search_query.py
+11
-10
No files found.
trans2es/commons/words_utils.py
View file @
1faad256
...
...
@@ -178,9 +178,9 @@ class QueryWordAttr(object):
def
get_search_query_results_num
(
cls
,
name
):
try
:
total_num
=
0
data
=
StrategyHistoryQueryWords
.
objects
.
filter
(
keyword
=
name
,
search_num__lte
=
7
)
.
values
(
"answer_num"
,
"tractate_num"
,
"diary_num"
)
.
first
()
data
=
StrategyHistoryQueryWords
.
objects
.
filter
(
keyword
=
name
,
search_num__lte
=
7
)
.
values
(
"answer_num"
,
"tractate_num"
,
"diary_num"
)
.
first
()
if
data
:
for
value
in
data
.
values
():
...
...
@@ -190,6 +190,48 @@ class QueryWordAttr(object):
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
0
@classmethod
def
save_query_to_redis
(
cls
,
query
,
from_type
=
None
):
try
:
lower_query
=
str
(
query
)
.
lower
()
key
=
"save_query_to_redis"
redis_data
=
redis_client
.
hget
(
key
,
lower_query
)
if
from_type
==
"search_query"
:
order_weight
=
cls
.
get_hot_search_query_word_weight
(
name
=
query
)
search_num
=
cls
.
get_search_query_results_num
(
name
=
query
)
else
:
order_weight
=
cls
.
get_project_query_word_weight
(
name
=
query
)
search_num
=
cls
.
get_query_results_num
(
name
=
query
)
if
redis_data
:
json_data
=
json
.
loads
(
redis_data
)
have_save_order_weight
=
json_data
.
get
(
'order_weight'
,
0
)
have_save_search_num
=
json_data
.
get
(
'order_weight'
,
0
)
if
have_save_order_weight
<
order_weight
:
redis_client
.
hset
(
key
,
lower_query
,
json
.
dumps
({
"order_weight"
:
order_weight
,
"search_num"
:
search_num
}))
return
True
elif
redis_data
==
order_weight
:
if
have_save_search_num
<
search_num
:
redis_client
.
hset
(
key
,
lower_query
,
json
.
dumps
({
"order_weight"
:
order_weight
,
"search_num"
:
search_num
}))
return
True
else
:
return
False
else
:
return
False
else
:
redis_client
.
hset
(
key
,
lower_query
,
json
.
dumps
({
"order_weight"
:
order_weight
,
"search_num"
:
search_num
}))
return
True
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
False
from
gm_rpcd.all
import
bind
from
libs.cache
import
redis_client
...
...
trans2es/management/commands/trans2es_mapping2es.py
View file @
1faad256
...
...
@@ -35,8 +35,11 @@ class Command(BaseCommand):
es_cli
=
ESPerform
.
get_cli
()
type_name1
=
"suggest-v1"
type_name
=
"suggest"
type_name2
=
"suggest-v2"
type_name3
=
"suggest-v3"
if
len
(
options
[
"type"
]):
if
options
[
"type"
]
==
"all"
or
type_name
==
options
[
"type"
]
or
type_name1
==
options
[
"type"
]:
if
options
[
"type"
]
==
"all"
or
type_name
==
options
[
"type"
]
or
type_name1
==
options
[
"type"
]
or
type_name2
==
options
[
'type'
]
or
type_name3
==
options
[
'type'
]
:
type_name
=
options
[
"type"
]
official_index_name
=
ESPerform
.
get_official_index_name
(
type_name
)
index_exists
=
es_cli
.
indices
.
exists
(
official_index_name
)
...
...
trans2es/mapping/suggest-v2.json
0 → 100644
View file @
1faad256
{
"dynamic"
:
"strict"
,
"properties"
:
{
"id"
:{
"type"
:
"text"
},
"suggest"
:{
"analyzer"
:
"keyword"
,
"search_analyzer"
:
"keyword"
,
"type"
:
"completion"
,
"contexts"
:[
{
"name"
:
"is_online"
,
"type"
:
"category"
}
]
},
"suggest_type"
:{
"type"
:
"long"
},
//
0
-汉字
,
1
-汉字全拼
,
2
-拼音
,
3
-拼音全拼
,
4
-拼音简写
,
5
-拼音简写全拼
"tips_name_type"
:{
"type"
:
"long"
},
//tips数据所属类型
,
0
-tag
,
1
-hospital
,
2
-doctor
,
3
-wiki
"ori_name"
:{
"type"
:
"keyword"
},
//原名称
"order_weight"
:{
"type"
:
"double"
},
//订单权重
"offline_score"
:{
"type"
:
"double"
},
//离线分
"results_num"
:{
"type"
:
"integer"
},
//结果数量
"type_flag"
:{
"type"
:
"keyword"
},
"is_online"
:{
"type"
:
"boolean"
}
//上线
}
}
trans2es/mapping/suggest-v3.json
0 → 100644
View file @
1faad256
{
"dynamic"
:
"strict"
,
"properties"
:
{
"id"
:{
"type"
:
"text"
},
"suggest"
:{
"analyzer"
:
"keyword"
,
"search_analyzer"
:
"keyword"
,
"type"
:
"completion"
,
"contexts"
:[
{
"name"
:
"is_online"
,
"type"
:
"category"
}
]
},
"suggest_type"
:{
"type"
:
"long"
},
//
0
-汉字
,
1
-汉字全拼
,
2
-拼音
,
3
-拼音全拼
,
4
-拼音简写
,
5
-拼音简写全拼
"tips_name_type"
:{
"type"
:
"long"
},
//tips数据所属类型
,
0
-tag
,
1
-hospital
,
2
-doctor
,
3
-wiki
"ori_name"
:{
"type"
:
"keyword"
},
//原名称
"order_weight"
:{
"type"
:
"double"
},
//订单权重
"offline_score"
:{
"type"
:
"double"
},
//离线分
"results_num"
:{
"type"
:
"integer"
},
//结果数量
"type_flag"
:{
"type"
:
"keyword"
},
"is_online"
:{
"type"
:
"boolean"
}
//上线
}
}
trans2es/utils/doctor_transfer.py
View file @
1faad256
...
...
@@ -94,7 +94,6 @@ class DoctorTransfer(object):
item_dict
[
"id"
]
=
getMd5Digest
(
str
(
instance
.
name
))
item_dict
[
"ori_name"
]
=
instance
.
name
item_dict
[
"is_online"
]
=
instance
.
is_online
item_dict
[
"order_weight"
]
=
QueryWordAttr
.
get_doctor_query_word_weight
(
instance
.
name
)
item_dict
[
"results_num"
]
=
QueryWordAttr
.
get_query_results_num
(
instance
.
name
)
item_dict
[
"type_flag"
]
=
get_tips_word_type
(
str
(
instance
.
name
)
.
lower
())
...
...
trans2es/utils/search_query.py
View file @
1faad256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import
logging
import
traceback
import
traceback
,
re
from
libs.tools
import
getMd5Digest
from
trans2es.commons.words_utils
import
QueryWordAttr
,
get_tips_word_type
from
trans2es.commons.commons
import
get_tips_suggest_list_v1
...
...
@@ -16,22 +16,23 @@ class SearchWord(object):
try
:
ret_list
=
list
()
item_dict
=
dict
()
item_dict
[
"id"
]
=
getMd5Digest
(
str
(
instance
.
keyword
))
item_dict
[
"ori_name"
]
=
instance
.
keyword
is_online
=
False
if
QueryWordAttr
.
get_search_query_results_num
(
instance
.
keyword
):
sub_query
=
re
.
sub
(
'
\
W+'
,
''
,
instance
.
keyword
)
keyword
=
str
(
sub_query
)
.
lower
()
item_dict
[
"id"
]
=
getMd5Digest
(
keyword
)
item_dict
[
"ori_name"
]
=
keyword
if
QueryWordAttr
.
get_search_query_results_num
(
keyword
):
is_online
=
False
if
instance
.
is_delete
else
True
else
:
is_online
=
False
item_dict
[
"is_online"
]
=
is_online
item_dict
[
"order_weight"
]
=
QueryWordAttr
.
get_hot_search_query_word_weight
(
instance
.
keyword
)
item_dict
[
"results_num"
]
=
QueryWordAttr
.
get_search_query_results_num
(
instance
.
keyword
)
item_dict
[
"type_flag"
]
=
get_tips_word_type
(
instance
.
keyword
)
item_dict
[
"order_weight"
]
=
QueryWordAttr
.
get_hot_search_query_word_weight
(
keyword
)
item_dict
[
"results_num"
]
=
QueryWordAttr
.
get_search_query_results_num
(
keyword
)
item_dict
[
"type_flag"
]
=
get_tips_word_type
(
keyword
)
item_dict
[
"offline_score"
]
=
0.0
item_dict
[
"tips_name_type"
]
=
5
ret_list
.
append
(
item_dict
)
suggest_list
=
get_tips_suggest_list_v1
(
str
(
instance
.
keyword
)
.
lower
()
)
suggest_list
=
get_tips_suggest_list_v1
(
keyword
)
return
(
item_dict
,
suggest_list
)
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