Fix FX model matching - prioritize exact matches
Browse files- Fixed issue where "FX 2" was incorrectly matching "FX SPORT 6"
- Added exact match priority scoring (score +100 for exact matches)
- Added prefix match scoring (score +50 for starts with)
- Remove year from product names during comparison
- Now correctly returns FX 2 at 51,000 TL instead of FX SPORT 6 at 183,000 TL
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
__pycache__/smart_warehouse_with_price.cpython-312.pyc
CHANGED
|
Binary files a/__pycache__/smart_warehouse_with_price.cpython-312.pyc and b/__pycache__/smart_warehouse_with_price.cpython-312.pyc differ
|
|
|
smart_warehouse_with_price.py
CHANGED
|
@@ -62,6 +62,9 @@ def get_product_price_and_link(product_name, variant=None):
|
|
| 62 |
best_match = None
|
| 63 |
best_score = 0
|
| 64 |
|
|
|
|
|
|
|
|
|
|
| 65 |
for item in root.findall('item'):
|
| 66 |
# Get product name
|
| 67 |
rootlabel_elem = item.find('rootlabel')
|
|
@@ -72,12 +75,24 @@ def get_product_price_and_link(product_name, variant=None):
|
|
| 72 |
for tr, en in tr_map.items():
|
| 73 |
item_name = item_name.replace(tr, en)
|
| 74 |
|
| 75 |
-
#
|
|
|
|
|
|
|
|
|
|
| 76 |
score = 0
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
# Check variant if specified
|
| 83 |
if variant and search_variant in item_name:
|
|
|
|
| 62 |
best_match = None
|
| 63 |
best_score = 0
|
| 64 |
|
| 65 |
+
# Clean search name - remove year and parentheses
|
| 66 |
+
clean_search = re.sub(r'\s*\(\d{4}\)\s*', '', search_name).strip()
|
| 67 |
+
|
| 68 |
for item in root.findall('item'):
|
| 69 |
# Get product name
|
| 70 |
rootlabel_elem = item.find('rootlabel')
|
|
|
|
| 75 |
for tr, en in tr_map.items():
|
| 76 |
item_name = item_name.replace(tr, en)
|
| 77 |
|
| 78 |
+
# Clean item name too
|
| 79 |
+
clean_item = re.sub(r'\s*\(\d{4}\)\s*', '', item_name).strip()
|
| 80 |
+
|
| 81 |
+
# Calculate match score with priority for exact matches
|
| 82 |
score = 0
|
| 83 |
+
|
| 84 |
+
# Exact match gets highest priority
|
| 85 |
+
if clean_search == clean_item:
|
| 86 |
+
score += 100
|
| 87 |
+
# Check if starts with exact product name (e.g., "fx 2" in "fx 2 kirmizi")
|
| 88 |
+
elif clean_item.startswith(clean_search + " ") or clean_item == clean_search:
|
| 89 |
+
score += 50
|
| 90 |
+
else:
|
| 91 |
+
# Partial matching
|
| 92 |
+
name_parts = clean_search.split()
|
| 93 |
+
for part in name_parts:
|
| 94 |
+
if part in clean_item:
|
| 95 |
+
score += 1
|
| 96 |
|
| 97 |
# Check variant if specified
|
| 98 |
if variant and search_variant in item_name:
|