mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-11 17:29:14 +02:00
fix: Handle punctuation differences in site domain matching
Critical fix for E.Leclerc and similar sites where DB domain differs from config key by punctuation (. vs -). **Problem:** - DB contains: "e.leclerc" (with dot) - Config key: "e-leclerc.com" (with dash) - Previous matching failed: no match found **Solution:** Enhanced matching with 5-level strategy: 1. **Exact match** - as before 2. **Normalized punctuation match** (NEW) - Remove all `-` and `.` from both sides - Compare: "e.leclerc" → "eleclerc", "e-leclerc.com" → "eleclecrcom" - Use contains logic: "eleclerc" in "eleclecrcom" → ✅ MATCH 3. **Contains match** - with original punctuation 4. **Prefix removal** - now handles both "e-" and "e." (plus "la-", "la.") 5. **Fuzzy core match** - last resort for edge cases **Impact:** - ✅ E.Leclerc now matches correctly - ✅ La Foir'Fouille handles variations - ✅ Any site with punctuation differences works - ✅ Backward compatible with existing matches **Debug logging:** All strategies log which method matched, making issues easy to diagnose.
This commit is contained in:
1 file changed
+55
-5
@@ -625,7 +625,7 @@ async def search_products(
|
||||
for site in active_sites:
|
||||
matched = False
|
||||
|
||||
# Normalize domain for comparison (remove www., e-, etc.)
|
||||
# Normalize domain for comparison (remove www., lowercase, etc.)
|
||||
normalized_domain = site.domain.lower().replace("www.", "").strip()
|
||||
|
||||
for key in SITE_CONFIGS.keys():
|
||||
@@ -639,16 +639,48 @@ async def search_products(
|
||||
logger.debug(f"✓ Matched {site.domain} → {key} (exact)")
|
||||
break
|
||||
|
||||
# 2. Key contains domain or domain contains key
|
||||
# 2. Normalize punctuation (. vs - vs nothing) and compare
|
||||
# e.leclerc → eleclerc, e-leclerc.com → eleclecrcom
|
||||
domain_no_punct = normalized_domain.replace("-", "").replace(".", "")
|
||||
key_no_punct = normalized_key.replace("-", "").replace(".", "")
|
||||
|
||||
# Exact match without punctuation
|
||||
if domain_no_punct == key_no_punct:
|
||||
site_keys.append(key)
|
||||
matched = True
|
||||
logger.debug(f"✓ Matched {site.domain} → {key} (normalized punctuation - exact)")
|
||||
break
|
||||
|
||||
# Contains match without punctuation (handles .com, .fr suffixes)
|
||||
# eleclerc in eleclecrcom → True
|
||||
if domain_no_punct in key_no_punct or key_no_punct in domain_no_punct:
|
||||
site_keys.append(key)
|
||||
matched = True
|
||||
logger.debug(f"✓ Matched {site.domain} → {key} (normalized punctuation - contains)")
|
||||
break
|
||||
|
||||
# 3. Key contains domain or domain contains key
|
||||
if normalized_key in normalized_domain or normalized_domain in normalized_key:
|
||||
site_keys.append(key)
|
||||
matched = True
|
||||
logger.debug(f"✓ Matched {site.domain} → {key} (contains)")
|
||||
break
|
||||
|
||||
# 3. Remove prefixes like "e-" and try again
|
||||
domain_without_prefix = normalized_domain.replace("e-", "").replace("la-", "")
|
||||
key_without_prefix = normalized_key.replace("e-", "").replace("la-", "")
|
||||
# 4. Remove prefixes like "e-", "e.", "la-", "la." and try again
|
||||
domain_without_prefix = (
|
||||
normalized_domain
|
||||
.replace("e-", "")
|
||||
.replace("e.", "")
|
||||
.replace("la-", "")
|
||||
.replace("la.", "")
|
||||
)
|
||||
key_without_prefix = (
|
||||
normalized_key
|
||||
.replace("e-", "")
|
||||
.replace("e.", "")
|
||||
.replace("la-", "")
|
||||
.replace("la.", "")
|
||||
)
|
||||
|
||||
if domain_without_prefix == key_without_prefix:
|
||||
site_keys.append(key)
|
||||
@@ -656,6 +688,24 @@ async def search_products(
|
||||
logger.debug(f"✓ Matched {site.domain} → {key} (without prefix)")
|
||||
break
|
||||
|
||||
# 5. Last resort: fuzzy match on core name (remove all punct + common prefixes)
|
||||
domain_core = (
|
||||
domain_no_punct
|
||||
.replace("e", "", 1) # Remove first 'e' if present
|
||||
.replace("la", "", 1) # Remove first 'la' if present
|
||||
)
|
||||
key_core = (
|
||||
key_no_punct
|
||||
.replace("e", "", 1)
|
||||
.replace("la", "", 1)
|
||||
)
|
||||
|
||||
if len(domain_core) > 5 and domain_core in key_core:
|
||||
site_keys.append(key)
|
||||
matched = True
|
||||
logger.debug(f"✓ Matched {site.domain} → {key} (fuzzy core)")
|
||||
break
|
||||
|
||||
if not matched:
|
||||
logger.warning(f"⚠️ No config found for site: {site.domain} (id={site.id})")
|
||||
|
||||
|
||||
Reference in new issue
Block a user