Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
chatbot canifa
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
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
Vũ Hoàng Anh
chatbot canifa
Commits
ffe458a6
Commit
ffe458a6
authored
May 11, 2026
by
Vũ Hoàng Anh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(search): robust color filter — strip 'Màu' prefix, VN→EN mapping, diacritics fallback
parent
94484304
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
2 deletions
+40
-2
search_engine.py
backend/agent/tools/tool_module/search_engine.py
+40
-2
No files found.
backend/agent/tools/tool_module/search_engine.py
View file @
ffe458a6
...
@@ -177,8 +177,46 @@ def _build_fixed_clauses(inf: InferredSearch, params: list) -> list[str]:
...
@@ -177,8 +177,46 @@ def _build_fixed_clauses(inf: InferredSearch, params: list) -> list[str]:
clauses
.
append
(
"age_by_product =
%
s"
)
clauses
.
append
(
"age_by_product =
%
s"
)
if
inf
.
master_color
:
if
inf
.
master_color
:
params
.
append
(
f
"
%
{inf.master_color}
%
"
);
params
.
append
(
f
"
%
{inf.master_color}
%
"
)
# ── Robust Color Filter ──
clauses
.
append
(
"(master_color LIKE
%
s OR product_color_name LIKE
%
s)"
)
# AI có thể output "Màu đen", "đen", "black" — DB lưu "Đen/ Black"
# Cần strip prefix + map VN→EN + bỏ dấu → thử tất cả patterns
import
unicodedata
as
_ucd
COLOR_VN_TO_EN
=
{
"đỏ"
:
"red"
,
"do"
:
"red"
,
"trắng"
:
"white"
,
"trang"
:
"white"
,
"đen"
:
"black"
,
"den"
:
"black"
,
"xanh"
:
"blue"
,
"xanh dương"
:
"blue"
,
"xanh da trời"
:
"blue"
,
"xanh lá"
:
"green"
,
"xanh la"
:
"green"
,
"hồng"
:
"pink"
,
"hong"
:
"pink"
,
"tím"
:
"purple"
,
"tim"
:
"purple"
,
"cam"
:
"orange"
,
"vàng"
:
"yellow"
,
"vang"
:
"yellow"
,
"nâu"
:
"brown"
,
"nau"
:
"brown"
,
"xám"
:
"gray"
,
"xam"
:
"gray"
,
"be"
:
"beige"
,
"kem"
:
"cream"
,
"bạc"
:
"silver"
,
"bac"
:
"silver"
,
"vàng đồng"
:
"gold"
,
"vang dong"
:
"gold"
,
}
c_raw
=
inf
.
master_color
.
strip
()
# Strip "Màu " / "màu " prefix (AI hay thêm)
import
re
as
_re
c_clean
=
_re
.
sub
(
r'^[Mm]àu\s+'
,
''
,
c_raw
)
# Bỏ dấu tiếng Việt
c_no_accent
=
""
.
join
(
ch
for
ch
in
_ucd
.
normalize
(
"NFD"
,
c_clean
.
lower
())
if
_ucd
.
category
(
ch
)
!=
"Mn"
)
.
strip
()
# Map sang English
en_color
=
COLOR_VN_TO_EN
.
get
(
c_clean
.
lower
())
or
COLOR_VN_TO_EN
.
get
(
c_no_accent
)
color_or_parts
=
[]
# Pattern 1: cleaned Vietnamese (e.g. "đen" matches "Đen/ Black")
color_or_parts
.
append
(
"(LOWER(master_color) LIKE
%
s OR LOWER(product_color_name) LIKE
%
s)"
)
params
.
extend
([
f
"
%
{c_clean.lower()}
%
"
,
f
"
%
{c_clean.lower()}
%
"
])
# Pattern 2: no-accent fallback (e.g. "den" matches)
if
c_no_accent
!=
c_clean
.
lower
():
color_or_parts
.
append
(
"(LOWER(master_color) LIKE
%
s OR LOWER(product_color_name) LIKE
%
s)"
)
params
.
extend
([
f
"
%
{c_no_accent}
%
"
,
f
"
%
{c_no_accent}
%
"
])
# Pattern 3: English color (e.g. "black" matches "Đen/ Black")
if
en_color
:
color_or_parts
.
append
(
"(LOWER(master_color) LIKE
%
s OR LOWER(product_color_name) LIKE
%
s)"
)
params
.
extend
([
f
"
%
{en_color}
%
"
,
f
"
%
{en_color}
%
"
])
clauses
.
append
(
"("
+
" OR "
.
join
(
color_or_parts
)
+
")"
)
if
inf
.
price_min
is
not
None
:
if
inf
.
price_min
is
not
None
:
params
.
append
(
inf
.
price_min
);
clauses
.
append
(
"sale_price >=
%
s"
)
params
.
append
(
inf
.
price_min
);
clauses
.
append
(
"sale_price >=
%
s"
)
...
...
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