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
423c62a0
Commit
423c62a0
authored
Aug 16, 2019
by
段英荣
1
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'wordres' into 'master'
Wordres See merge request
!24
parents
dbf52cb1
367c9627
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
39 deletions
+70
-39
auto_tips.py
search/utils/auto_tips.py
+30
-16
type_info.py
trans2es/type_info.py
+3
-3
wordresemble.py
trans2es/utils/wordresemble.py
+37
-20
No files found.
search/utils/auto_tips.py
View file @
423c62a0
...
@@ -38,8 +38,6 @@ def get_suggest_tips(query, lat, lng, offset=0, size=50):
...
@@ -38,8 +38,6 @@ def get_suggest_tips(query, lat, lng, offset=0, size=50):
#
#
# logging.info("get whole_query:%s" % whole_query)
# logging.info("get whole_query:%s" % whole_query)
# hits = whole_query["hits"]["hits"]
# hits = whole_query["hits"]["hits"]
#
#
# for item in hits:
# for item in hits:
...
@@ -169,21 +167,37 @@ def get_suggest_tips(query, lat, lng, offset=0, size=50):
...
@@ -169,21 +167,37 @@ def get_suggest_tips(query, lat, lng, offset=0, size=50):
return
ret_list
return
ret_list
else
:
else
:
QUERY_KEY
=
"query:{}:search_tip"
query_ret_list
=
[]
wordresemble_ret_list
=
[]
value_data
=
[]
QUERY_KEY
=
"query:search_tip"
query_base64
=
base64
.
b64encode
(
query
.
encode
(
'utf8'
))
.
decode
(
'utf8'
)
query_base64
=
base64
.
b64encode
(
query
.
encode
(
'utf8'
))
.
decode
(
'utf8'
)
key
=
QUERY_KEY
.
format
(
query_base64
)
if
redis_client
.
hget
(
QUERY_KEY
,
query_base64
)
is
not
None
:
labels
=
list
(
map
(
lambda
x
:
x
.
decode
(
"utf8"
),
list
(
redis_client
.
smembers
(
key
))))
value_data
=
json
.
loads
(
redis_client
.
hget
(
QUERY_KEY
,
query_base64
))
for
i
in
labels
:
ori
=
i
.
split
(
":"
)[
0
]
if
len
(
value_data
)
>
0
:
ori_name
=
base64
.
b64decode
(
ori
.
encode
(
'utf8'
))
.
decode
(
'utf8'
)
for
i
in
value_data
:
if
ori_name
not
in
have_read_tips_set
:
key
=
list
(
i
.
keys
())[
0
]
have_read_tips_set
.
add
(
ori_name
)
ori_name
=
str
(
base64
.
b64decode
(
key
),
"utf-8"
)
result_num
=
i
.
split
(
":"
)[
1
]
if
ori_name
not
in
have_read_tips_set
:
ret_list
.
append
(
have_read_tips_set
.
add
(
ori_name
)
{
"results_num"
:
result_num
,
"ori_name"
:
ori_name
,
"id"
:
None
,
"is_online"
:
True
,
result_num
=
i
.
get
(
key
,
0
)
"offline_score"
:
0
,
highlight_marks
=
u'<ems>
%
s</ems>'
%
query
"type_flag"
:
get_tips_word_type
(
ori_name
),
"highlight_name"
:
ori_name
,
"describe"
:
""
})
highlight_name
=
ori_name
.
replace
(
query
,
highlight_marks
)
if
ori_name
==
query
:
query_ret_list
.
append
(
{
"results_num"
:
result_num
,
"ori_name"
:
ori_name
,
"id"
:
None
,
"is_online"
:
True
,
"offline_score"
:
0
,
"type_flag"
:
get_tips_word_type
(
ori_name
),
"highlight_name"
:
highlight_name
,
"describe"
:
""
})
else
:
wordresemble_ret_list
.
append
(
{
"results_num"
:
result_num
,
"ori_name"
:
ori_name
,
"id"
:
None
,
"is_online"
:
True
,
"offline_score"
:
0
,
"type_flag"
:
get_tips_word_type
(
ori_name
),
"highlight_name"
:
highlight_name
,
"describe"
:
""
})
ret_list
.
extend
(
query_ret_list
)
ret_list
.
extend
(
wordresemble_ret_list
)
if
len
(
ret_list
)
>=
50
:
if
len
(
ret_list
)
>=
50
:
return
ret_list
[
0
:
50
]
return
ret_list
[
0
:
50
]
...
...
trans2es/type_info.py
View file @
423c62a0
...
@@ -538,8 +538,8 @@ def tips_attr_sync_to_redis_type_info_map():
...
@@ -538,8 +538,8 @@ def tips_attr_sync_to_redis_type_info_map():
),
),
TypeInfo
(
TypeInfo
(
name
=
'suggest'
,
name
=
'suggest'
,
type
=
'wordrel_results_num'
,
# api_wordrel
resemble
type
=
'wordrel_results_num'
,
# api_wordrel
model
=
doctor
.
Hospita
l
,
model
=
wordresemble
.
WordRe
l
,
query_deferred
=
lambda
:
wordresemble
.
WordRel
.
objects
.
filter
(
query_deferred
=
lambda
:
wordresemble
.
WordRel
.
objects
.
filter
(
category__in
=
[
13
,
12
,
11
,
9
,
1
])
.
query
,
category__in
=
[
13
,
12
,
11
,
9
,
1
])
.
query
,
get_data_func
=
WordResemble
.
get_all_data_name_mapping_results_to_redis
,
get_data_func
=
WordResemble
.
get_all_data_name_mapping_results_to_redis
,
...
@@ -550,7 +550,7 @@ def tips_attr_sync_to_redis_type_info_map():
...
@@ -550,7 +550,7 @@ def tips_attr_sync_to_redis_type_info_map():
TypeInfo
(
TypeInfo
(
name
=
'suggest'
,
name
=
'suggest'
,
type
=
'wordresemble_results_num'
,
# api_wordrelresemble
type
=
'wordresemble_results_num'
,
# api_wordrelresemble
model
=
doctor
.
Hospita
l
,
model
=
wordresemble
.
WordRe
l
,
query_deferred
=
lambda
:
wordresemble
.
WordRel
.
objects
.
filter
(
query_deferred
=
lambda
:
wordresemble
.
WordRel
.
objects
.
filter
(
category__in
=
[
13
,
12
,
11
,
9
,
1
])
.
query
,
category__in
=
[
13
,
12
,
11
,
9
,
1
])
.
query
,
get_data_func
=
WordResemble
.
set_data_to_redis
,
get_data_func
=
WordResemble
.
set_data_to_redis
,
...
...
trans2es/utils/wordresemble.py
View file @
423c62a0
...
@@ -88,6 +88,23 @@ class WordResemble(object):
...
@@ -88,6 +88,23 @@ class WordResemble(object):
# 获取日记的
# 获取日记的
WordResemble
.
get_diary_data_name_mapping_results_to_redis
(
instance
)
WordResemble
.
get_diary_data_name_mapping_results_to_redis
(
instance
)
# 获取该关键词的同义词的数据
query_sql_item
=
wordresemble
.
WordRelResemble
.
objects
.
filter
(
wordrel_id
=
instance
.
id
)
if
query_sql_item
:
for
item
in
query_sql_item
:
instance
.
name
=
item
.
word
# 获取百科的
ItemWikiTransfer
.
get_wiki_data_name_mapping_results_to_redis
(
instance
)
# 获取美购的
TagTransfer
.
get_tag_data_name_mapping_results_to_redis
(
instance
)
# 获取医生医院的
DoctorTransfer
.
get_doctor_data_name_mapping_results_to_redis
(
instance
)
# 获取日记的
WordResemble
.
get_diary_data_name_mapping_results_to_redis
(
instance
)
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
@@ -153,41 +170,37 @@ class WordResemble(object):
...
@@ -153,41 +170,37 @@ class WordResemble(object):
def
set_data_to_redis
(
cls
,
instance
):
def
set_data_to_redis
(
cls
,
instance
):
try
:
try
:
QUERY_KEY
=
"query:{}:search_tip"
keyword_value
=
[]
QUERY_KEY
=
"query:search_tip"
tips_num_redis_key_prefix
=
"search_tips:tips_mapping_num"
tips_num_redis_key_prefix
=
"search_tips:tips_mapping_num"
query_sql_item
=
wordresemble
.
WordRel
.
objects
.
filter
(
keyword
=
instance
.
keyword
)
query_sql_item
=
wordresemble
.
WordRel
.
objects
.
filter
(
keyword
=
instance
.
keyword
)
for
sql_obj
in
query_sql_item
:
for
sql_obj
in
query_sql_item
:
count
=
0
words
=
list
(
sql_obj
.
all_resembles
.
all
()
.
values_list
(
'word'
,
flat
=
True
))
words
=
list
(
sql_obj
.
all_resembles
.
all
()
.
values_list
(
'word'
,
flat
=
True
))
query_base64
=
base64
.
b64encode
(
instance
.
keyword
.
encode
(
'utf8'
))
.
decode
(
'utf8'
)
for
items
in
words
:
for
items
in
words
:
count
+=
1
wordresemble_value
=
[]
# 先存储本体词
# 先存储本体词
query_base64
=
base64
.
b64encode
(
instance
.
keyword
.
encode
(
'utf8'
))
.
decode
(
'utf8'
)
item_name
=
base64
.
b64encode
(
items
.
encode
(
'utf8'
))
.
decode
(
'utf8'
)
key
=
QUERY_KEY
.
format
(
query_base64
)
# 获取该同义词的结果
value_name
=
base64
.
b64encode
(
items
.
encode
(
'utf8'
))
.
decode
(
'utf8'
)
# 获取本体词的结果
redis_data
=
redis_client
.
hget
(
tips_num_redis_key_prefix
,
items
)
redis_data
=
redis_client
.
hget
(
tips_num_redis_key_prefix
,
items
)
logging
.
info
(
"get redis_data:
%
s"
%
redis_data
)
logging
.
info
(
"get redis_data:
%
s"
%
redis_data
)
redis_val_dict
=
json
.
loads
(
str
(
redis_data
,
encoding
=
"utf-8"
))
if
redis_data
else
{}
redis_val_dict
=
json
.
loads
(
str
(
redis_data
,
encoding
=
"utf-8"
))
if
redis_data
else
{}
total_count
=
0
total_count
=
0
if
't'
in
redis_val_dict
:
if
't'
in
redis_val_dict
:
total_count
=
int
(
redis_val_dict
[
't'
])
total_count
=
int
(
redis_val_dict
[
't'
])
# 存储到Redis
value
=
{
item_name
:
total_count
}
value
=
value_name
+
str
(
":"
+
str
(
total_count
))
keyword_value
.
append
(
value
)
redis_client
.
sadd
(
key
,
value
)
# 存储近义词
# query_base64 = base64.b64encode(items.encode('utf8')).decode('utf8')
key
=
QUERY_KEY
.
format
(
value_name
)
# value_name = base64.b64encode(wordrm["keyword"].encode('utf8')).decode('utf8')
value_names
=
query_base64
# 获取结果
redis_data
=
redis_client
.
hget
(
tips_num_redis_key_prefix
,
instance
.
keyword
)
redis_data
=
redis_client
.
hget
(
tips_num_redis_key_prefix
,
instance
.
keyword
)
redis_val_dict
=
json
.
loads
(
str
(
redis_data
,
encoding
=
"utf-8"
))
if
redis_data
else
{}
redis_val_dict
=
json
.
loads
(
str
(
redis_data
,
encoding
=
"utf-8"
))
if
redis_data
else
{}
total_count
=
0
total_count
=
0
if
't'
in
redis_val_dict
:
if
't'
in
redis_val_dict
:
total_count
=
int
(
redis_val_dict
[
't'
])
total_count
=
int
(
redis_val_dict
[
't'
])
# 存储结果
value
=
{
query_base64
:
total_count
}
value
=
value_names
+
str
(
":"
+
str
(
total_count
))
wordresemble_value
.
append
(
value
)
redis_client
.
sadd
(
key
,
value
)
if
count
==
1
:
keyword_value
.
append
(
value
)
if
words
:
if
words
:
for
w
in
words
:
for
w
in
words
:
value_name_w
=
base64
.
b64encode
(
w
.
encode
(
'utf8'
))
.
decode
(
'utf8'
)
value_name_w
=
base64
.
b64encode
(
w
.
encode
(
'utf8'
))
.
decode
(
'utf8'
)
...
@@ -196,8 +209,12 @@ class WordResemble(object):
...
@@ -196,8 +209,12 @@ class WordResemble(object):
total_count
=
0
total_count
=
0
if
't'
in
redis_val_dict
:
if
't'
in
redis_val_dict
:
total_count
=
int
(
redis_val_dict
[
't'
])
total_count
=
int
(
redis_val_dict
[
't'
])
value
=
value_name_w
+
str
(
":"
+
str
(
total_count
))
value
=
{
value_name_w
:
total_count
}
redis_client
.
sadd
(
key
,
value
)
wordresemble_value
.
append
(
value
)
if
len
(
wordresemble_value
)
>
0
:
redis_client
.
hset
(
QUERY_KEY
,
item_name
,
json
.
dumps
(
wordresemble_value
))
if
len
(
keyword_value
)
>
0
:
redis_client
.
hset
(
QUERY_KEY
,
query_base64
,
json
.
dumps
(
keyword_value
))
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
李小芳
@lixiaofang
mentioned in commit
0db0bc46
·
Aug 16, 2019
mentioned in commit
0db0bc46
mentioned in commit 0db0bc4661c834bb8b88592cf111987a9f236fa5
Toggle commit list
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