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
8ebb295a
Commit
8ebb295a
authored
Jun 11, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add
parent
d4ebe787
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
48 deletions
+49
-48
wordresemble.py
trans2es/utils/wordresemble.py
+49
-48
No files found.
trans2es/utils/wordresemble.py
View file @
8ebb295a
...
...
@@ -149,54 +149,55 @@ class WordResemble(object):
QUERY_KEY
=
"query:{}:search_tips"
tips_num_redis_key_prefix
=
"search_tips:tips_mapping_num"
result
=
wordresemble
.
WordRel
.
objects
.
all
()
.
values
(
"keyword"
,
"id"
)
for
wordrm
in
result
:
query_sql_item
=
wordresemble
.
WordRel
.
objects
.
filter
(
keyword
=
wordrm
[
"keyword"
])
for
sql_obj
in
query_sql_item
:
words
=
list
(
sql_obj
.
all_resembles
.
all
()
.
values_list
(
'word'
,
flat
=
True
))
logging
.
info
(
"get words:
%
s"
%
words
)
for
items
in
words
:
# 先存储本体词
query_base64
=
base64
.
b64encode
(
wordrm
[
"keyword"
]
.
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_val_dict
=
json
.
loads
(
str
(
redis_data
,
encoding
=
"utf-8"
))
if
redis_data
else
{}
total_count
=
0
if
't'
in
redis_val_dict
:
total_count
=
int
(
redis_val_dict
[
't'
])
# 存储到Redis
logging
.
info
(
"get items:
%
s"
%
items
)
value
=
value_name
+
str
(
":"
+
str
(
total_count
))
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
,
wordrm
[
"keyword"
])
redis_val_dict
=
json
.
loads
(
str
(
redis_data
,
encoding
=
"utf-8"
))
if
redis_data
else
{}
total_count
=
0
if
't'
in
redis_val_dict
:
total_count
=
int
(
redis_val_dict
[
't'
])
# 存储结果
value
=
value_names
+
str
(
":"
+
str
(
total_count
))
redis_client
.
sadd
(
key
,
value
)
if
words
:
for
w
in
words
:
value_name_w
=
base64
.
b64encode
(
w
.
encode
(
'utf8'
))
.
decode
(
'utf8'
)
redis_data
=
redis_client
.
hget
(
tips_num_redis_key_prefix
,
w
)
redis_val_dict
=
json
.
loads
(
str
(
redis_data
,
encoding
=
"utf-8"
))
if
redis_data
else
{}
total_count
=
0
if
't'
in
redis_val_dict
:
total_count
=
int
(
redis_val_dict
[
't'
])
value
=
value_name_w
+
str
(
":"
+
str
(
total_count
))
redis_client
.
sadd
(
key
,
value
)
# result = wordresemble.WordRel.objects.all().values("keyword", "id")
# for wordrm in result:
logging
.
info
(
"get instance:
%
s"
%
instance
.
keyword
)
query_sql_item
=
wordresemble
.
WordRel
.
objects
.
filter
(
keyword
=
instance
.
keyword
)
for
sql_obj
in
query_sql_item
:
words
=
list
(
sql_obj
.
all_resembles
.
all
()
.
values_list
(
'word'
,
flat
=
True
))
logging
.
info
(
"get words:
%
s"
%
words
)
for
items
in
words
:
# 先存储本体词
query_base64
=
base64
.
b64encode
(
instance
.
keyword
.
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_val_dict
=
json
.
loads
(
str
(
redis_data
,
encoding
=
"utf-8"
))
if
redis_data
else
{}
total_count
=
0
if
't'
in
redis_val_dict
:
total_count
=
int
(
redis_val_dict
[
't'
])
# 存储到Redis
logging
.
info
(
"get items:
%
s"
%
items
)
value
=
value_name
+
str
(
":"
+
str
(
total_count
))
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_val_dict
=
json
.
loads
(
str
(
redis_data
,
encoding
=
"utf-8"
))
if
redis_data
else
{}
total_count
=
0
if
't'
in
redis_val_dict
:
total_count
=
int
(
redis_val_dict
[
't'
])
# 存储结果
value
=
value_names
+
str
(
":"
+
str
(
total_count
))
redis_client
.
sadd
(
key
,
value
)
if
words
:
for
w
in
words
:
value_name_w
=
base64
.
b64encode
(
w
.
encode
(
'utf8'
))
.
decode
(
'utf8'
)
redis_data
=
redis_client
.
hget
(
tips_num_redis_key_prefix
,
w
)
redis_val_dict
=
json
.
loads
(
str
(
redis_data
,
encoding
=
"utf-8"
))
if
redis_data
else
{}
total_count
=
0
if
't'
in
redis_val_dict
:
total_count
=
int
(
redis_val_dict
[
't'
])
value
=
value_name_w
+
str
(
":"
+
str
(
total_count
))
redis_client
.
sadd
(
key
,
value
)
except
:
logging
.
error
(
"catch exception,err_msg:
%
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