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
30985760
Commit
30985760
authored
Aug 14, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add
parent
f76cff30
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
118 additions
and
2 deletions
+118
-2
develop_server.py
develop_server.py
+31
-0
auto_tips.py
search/utils/auto_tips.py
+87
-1
commons.py
trans2es/commons/commons.py
+0
-1
No files found.
develop_server.py
0 → 100644
View file @
30985760
import
sys
from
gm_rpcd.commands.utils
import
add_cwd_to_path
from
gm_rpcd.internals.utils
import
serve
def
main
(
args
):
add_cwd_to_path
()
from
gm_rpcd.internals.configuration
import
config
config
.
is_develop_mode
=
True
config
.
freeze
()
host
=
'127.0.0.1'
port
=
9000
try
:
first_arg
=
args
[
0
]
except
IndexError
:
pass
else
:
if
':'
in
first_arg
:
host
,
port
=
first_arg
.
split
(
':'
)
port
=
int
(
port
)
else
:
port
=
int
(
first_arg
)
print
(
'Serving on {}:{}'
.
format
(
host
,
port
))
serve
(
host
=
host
,
port
=
port
)
if
__name__
==
'__main__'
:
main
(
sys
.
argv
[
1
:])
search/utils/auto_tips.py
View file @
30985760
...
...
@@ -16,6 +16,83 @@ from trans2es.commons.words_utils import QueryWordAttr, get_tips_word_type
def
get_suggest_tips
(
query
,
lat
,
lng
,
offset
=
0
,
size
=
50
):
try
:
###先获取完全命中的query
qq
=
{
"query"
:
{
"bool"
:
{
"must"
:
[{
"term"
:
{
"ori_name"
:
query
}
},
{
"term"
:
{
"is_online"
:
True
}
}]
}
}
}
logging
.
info
(
"get qqqqqqqqq:
%
s"
%
qq
)
whole_query
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
"suggest"
,
query_body
=
qq
,
offset
=
0
,
size
=
1
,
is_suggest_request
=
True
)
logging
.
info
(
"get whole_query:
%
s"
%
whole_query
)
have_read_tips_set
=
set
()
ret_list
=
list
()
get_doctor_hospital_data
=
list
()
get_tag_wiki_data
=
list
()
hits
=
whole_query
[
"hits"
][
"hits"
]
for
item
in
hits
:
have_read_tips_set
.
add
(
item
[
"_source"
][
"ori_name"
])
id
=
item
[
"_source"
][
"id"
]
ori_name
=
item
[
"_source"
][
"ori_name"
]
results_num
=
item
[
"_source"
][
"results_num"
]
is_online
=
item
[
"_source"
][
"is_online"
]
offline_score
=
item
[
"_source"
][
"offline_score"
]
type_flag
=
item
[
"_source"
][
"type_flag"
]
highlight_marks
=
u'<ems>
%
s</ems>'
%
query
item
[
"_source"
][
"highlight_name"
]
=
item
[
"_source"
][
"ori_name"
]
.
replace
(
query
,
highlight_marks
)
highlight_name
=
item
[
"_source"
][
"highlight_name"
]
if
item
[
"_source"
][
"type_flag"
]
==
"hospital"
:
if
lat
is
not
None
and
lng
is
not
None
and
lat
!=
0.0
and
lng
!=
0.0
:
logging
.
info
(
"get g_hospital_pos_dict:
%
s"
%
g_hospital_pos_dict
)
if
item
[
"_source"
][
"ori_name"
]
in
g_hospital_pos_dict
:
distance
=
point_distance
(
lng
,
lat
,
g_hospital_pos_dict
[
item
[
"_source"
][
"ori_name"
]][
0
],
g_hospital_pos_dict
[
item
[
"_source"
][
"ori_name"
]][
1
])
if
distance
<
1000
*
50
:
if
distance
<
1000
:
if
distance
<
100
:
item
[
"_source"
][
"describe"
]
=
"<100"
+
"米"
else
:
item
[
"_source"
][
"describe"
]
=
"约"
+
str
(
int
(
distance
))
+
"米"
else
:
item
[
"_source"
][
"describe"
]
=
"约"
+
str
(
round
(
1.0
*
distance
/
1000
,
1
))
+
"km"
else
:
item
[
"_source"
][
"describe"
]
=
">50km"
else
:
item
[
"_source"
][
"describe"
]
=
""
else
:
item
[
"_source"
][
"describe"
]
=
""
else
:
if
item
[
"_source"
][
"type_flag"
]
==
"doctor"
:
item
[
"_source"
][
"describe"
]
=
""
else
:
item
[
"_source"
][
"describe"
]
=
"约"
+
str
(
item
[
"_source"
][
"results_num"
])
+
"个结果"
if
\
item
[
"_source"
][
"results_num"
]
else
""
ret_list
.
append
({
"offline_score"
:
offline_score
,
"ori_name"
:
ori_name
,
"results_num"
:
results_num
,
"id"
:
id
,
"highlight_name"
:
highlight_name
,
"type_flag"
:
type_flag
,
"is_online"
:
is_online
})
###获取联想到的数据
# ios输入法在某些情况下会携带\\u2006
query
=
query
.
replace
(
"
\u2006
"
,
''
)
q
=
{
...
...
@@ -75,13 +152,22 @@ def get_suggest_tips(query, lat, lng, offset=0, size=50):
else
:
hit_item
[
"_source"
][
"describe"
]
=
""
get_doctor_hospital_data
.
append
(
hit_item
[
"_source"
])
else
:
if
hit_item
[
"_source"
][
"type_flag"
]
==
"doctor"
:
hit_item
[
"_source"
][
"describe"
]
=
""
get_doctor_hospital_data
.
append
(
hit_item
[
"_source"
])
else
:
hit_item
[
"_source"
][
"describe"
]
=
"约"
+
str
(
hit_item
[
"_source"
][
"results_num"
])
+
"个结果"
if
\
hit_item
[
"_source"
][
"results_num"
]
else
""
ret_list
.
append
(
hit_item
[
"_source"
])
get_tag_wiki_data
.
append
(
hit_item
[
"_source"
])
logging
.
info
(
"get get_doctor_hospital_data:
%
s"
%
get_doctor_hospital_data
)
logging
.
info
(
"get get_tag_wiki_data:
%
s"
%
get_tag_wiki_data
)
ret_list
.
extend
(
get_tag_wiki_data
)
ret_list
.
extend
(
get_doctor_hospital_data
)
if
len
(
result_dict
[
"suggest"
][
"tips-suggest"
])
>=
50
:
return
ret_list
...
...
trans2es/commons/commons.py
View file @
30985760
...
...
@@ -17,7 +17,6 @@ def uuid4():
"""
return
uuid
.
uuid4
()
.
hex
def
get_tips_suggest_list
(
instance_cn_name
):
try
:
# ch_full_weight = 6.0 * 1000
...
...
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