fix: Make distillery fuzzy matching stricter
- Threshold: 0.25 (was 0.4) - Score check: 0.3 (was 0.5) - minMatchCharLength: 4 (was 3) Prevents false positives like 'Kilkeran' → 'Glenglassaugh'
This commit is contained in:
@@ -24,10 +24,10 @@ const STOPWORDS = [
|
||||
// Initialize Fuse.js with distilleries
|
||||
const fuse = new Fuse<Distillery>(distilleries as Distillery[], {
|
||||
keys: ['name'],
|
||||
threshold: 0.4, // Fuzzy tolerance (0 = exact, 1 = match anything)
|
||||
threshold: 0.25, // Stricter fuzzy tolerance (was 0.4)
|
||||
includeScore: true,
|
||||
ignoreLocation: true,
|
||||
minMatchCharLength: 3,
|
||||
minMatchCharLength: 4,
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -80,10 +80,30 @@ export function normalizeDistillery(rawName: string): {
|
||||
};
|
||||
}
|
||||
|
||||
// Fuzzy match with Fuse.js
|
||||
// Try partial/contains match for cases like "Kilkeran" in name "Kilkerran"
|
||||
// or input contains distillery name
|
||||
const partialMatch = (distilleries as Distillery[]).find(d => {
|
||||
const dLower = d.name.toLowerCase();
|
||||
const pLower = preprocessed.toLowerCase();
|
||||
// Check if one contains the other (with at least 5 chars overlap)
|
||||
return (dLower.includes(pLower) && pLower.length >= 5) ||
|
||||
(pLower.includes(dLower) && dLower.length >= 5);
|
||||
});
|
||||
|
||||
if (partialMatch) {
|
||||
console.log(`[DistilleryMatcher] Partial match: "${rawName}" → "${partialMatch.name}"`);
|
||||
return {
|
||||
name: partialMatch.name,
|
||||
region: partialMatch.region,
|
||||
matched: true,
|
||||
score: 0.1
|
||||
};
|
||||
}
|
||||
|
||||
// Fuzzy match with Fuse.js (stricter threshold)
|
||||
const results = fuse.search(preprocessed);
|
||||
|
||||
if (results.length > 0 && results[0].score !== undefined && results[0].score < 0.5) {
|
||||
if (results.length > 0 && results[0].score !== undefined && results[0].score < 0.3) {
|
||||
const match = results[0].item;
|
||||
console.log(`[DistilleryMatcher] Fuzzy match: "${rawName}" → "${match.name}" (score: ${results[0].score?.toFixed(3)})`);
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user