Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
岳巧源
/
my-awesome-project
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a0316310
authored
Jun 20, 2024
by
larosa
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
match the table and request to es
parent
00da6858
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
2 deletions
main.py
main.py
View file @
a0316310
...
@@ -79,17 +79,34 @@ def main():
...
@@ -79,17 +79,34 @@ def main():
df
=
pd
.
read_excel
(
'table.xlsx'
)
df
=
pd
.
read_excel
(
'table.xlsx'
)
data
=
df
.
iloc
[:,
[
0
]]
.
values
data
=
df
.
iloc
[:,
[
0
]]
.
values
ans
=
[]
ans
=
[]
result
=
[]
for
i
in
range
(
len
(
data
)):
for
i
in
range
(
len
(
data
)):
if
i
>
10
:
break
# for debug, don't forget to delete this line.
sku_name_str
=
data
[
i
][
0
]
sku_name_str
=
data
[
i
][
0
]
res_tmp
=
match_sku
(
sku_name_str
)
res_tmp
=
match_sku
(
sku_name_str
)
ans
.
append
(
res_tmp
)
ans
.
append
(
res_tmp
)
for
i
in
range
(
len
(
ans
)):
for
i
in
range
(
len
(
ans
)):
score_in_one_row
=
[]
for
j
in
range
(
len
(
ans
[
i
])):
for
j
in
range
(
len
(
ans
[
i
])):
tmp_goods_name
=
ans
[
i
][
j
]
tmp_goods_name
=
ans
[
i
][
j
]
tmp_query
=
query
tmp_query
=
query
tmp_query
[
"query"
][
"bool"
][
"must"
][
0
][
"match"
][
"goods_name"
]
=
tmp_goods_name
tmp_query
[
"query"
][
"bool"
][
"must"
][
0
][
"match"
][
"goods_name"
]
=
tmp_goods_name
tmp_map
=
process
(
tmp_query
)
if
len
(
tmp_map
)
!=
0
:
score_in_one_row
.
append
(
tmp_map
)
if
len
(
score_in_one_row
)
==
0
:
continue
else
:
max_score
=
score_in_one_row
[
0
]
.
get
(
"score"
)
index
=
0
for
k
in
range
(
len
(
score_in_one_row
)):
if
score_in_one_row
[
k
]
.
get
(
"score"
)
>
max_score
:
max_score
=
score_in_one_row
[
k
]
.
get
(
"score"
)
index
=
k
result
.
append
(
score_in_one_row
[
index
])
return
result
def
match_sku
(
s
:
str
)
->
[]:
def
match_sku
(
s
:
str
)
->
[]:
# s = "RG58/U射频连接线SMA公头转BNC公头延长线 SMA/BNC-JJ Q9/SMA-JJ RG58/U-SMA/BNC-JJ 2m"
# s = "RG58/U射频连接线SMA公头转BNC公头延长线 SMA/BNC-JJ Q9/SMA-JJ RG58/U-SMA/BNC-JJ 2m"
...
@@ -124,6 +141,19 @@ def post_to_elasticsearch(q: dict):
...
@@ -124,6 +141,19 @@ def post_to_elasticsearch(q: dict):
ans
=
response
.
json
()
ans
=
response
.
json
()
return
ans
return
ans
def
process
(
query_str
:
dict
):
res
=
post_to_elasticsearch
(
query_str
)
if
res
[
"hits"
][
"max_score"
]
is
not
None
and
res
[
"hits"
][
"max_score"
]
>
80
:
for
i
in
range
(
len
(
res
[
"hits"
][
"hits"
])):
if
res
[
"hits"
][
"hits"
][
i
][
"_score"
]
==
res
[
"hits"
][
"max_score"
]:
_score
=
res
[
"hits"
][
"hits"
][
i
][
"_score"
]
_goods_name
=
res
[
"hits"
][
"hits"
][
i
][
"_source"
][
"goods_name"
]
_goods_id
=
res
[
"hits"
][
"hits"
][
i
][
"_source"
][
"goods_id"
]
_brand_name
=
res
[
"hits"
][
"hits"
][
i
][
"_source"
][
"brand_name"
]
return
{
"goods_name"
:
_goods_name
,
"goods_id"
:
_goods_id
,
"brand_name"
:
_brand_name
,
"score"
:
_score
}
return
{}
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
main
()
res
=
main
()
print
(
res
)
\ No newline at end of file
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