// Debug script to test exact "BL Test Env" vs "Reseller-1" word matching
console.log('🧪 Testing BL Test Env vs Reseller-1 word matching logic\n');
const query = "show me Bank Leumi Test Env costs last 6 months";
const queryLower = query.toLowerCase();
const accounts = [
{ accountName: "BL Test Env", accountKey: "24223", divisionId: "1" },
{ accountName: "Reseller-1", accountKey: "22676", divisionId: "?" }
];
console.log(`Query: "${query}"`);
console.log(`Query lower: "${queryLower}"`);
// Extract meaningful words from query (same logic as server)
const queryWords = queryLower.split(/[\s-]+/).filter(w => w.length > 2);
console.log(`Query words (length > 2): [${queryWords.map(w => `"${w}"`).join(', ')}]`);
console.log('\n--- Testing each account ---\n');
accounts.forEach((account, index) => {
console.log(`${index + 1}. Account: "${account.accountName}" (key: ${account.accountKey})`);
const accountNameLower = account.accountName.toLowerCase();
console.log(` Account name lower: "${accountNameLower}"`);
// Extract meaningful words from account name (same logic as server)
const accountWords = accountNameLower.split(/[\s-]+/).filter(w => w.length > 2);
console.log(` Account words (length > 2): [${accountWords.map(w => `"${w}"`).join(', ')}]`);
// Check for word overlap (same logic as server)
const matchingWords = accountWords.filter(word =>
queryWords.some(qWord => qWord.includes(word) || word.includes(qWord))
);
console.log(` Matching words: [${matchingWords.map(w => `"${w}"`).join(', ')}]`);
// Apply server matching conditions
const fullNameMatch = queryLower.includes(accountNameLower);
const wordCountMatch = matchingWords.length >= Math.min(2, accountWords.length);
const partialMatch = accountNameLower.split(/[\s-]+/).some(part => part.length > 3 && queryLower.includes(part));
console.log(` Full name match (queryLower.includes(accountNameLower)): ${fullNameMatch}`);
console.log(` Word count match (${matchingWords.length} >= min(2, ${accountWords.length})): ${wordCountMatch}`);
console.log(` Partial match (part > 3 chars in query): ${partialMatch}`);
const isMatch = fullNameMatch || wordCountMatch || partialMatch;
console.log(` ✨ FINAL RESULT: ${isMatch ? '✅ MATCH' : '❌ NO MATCH'}`);
if (isMatch && account.accountName === "BL Test Env") {
console.log(` 🎯 SUCCESS: BL Test Env should be selected!`);
} else if (isMatch && account.accountName === "Reseller-1") {
console.log(` ⚠️ PROBLEM: Reseller-1 is matching when it shouldn't!`);
}
console.log('');
});
console.log('🔍 Analysis:');
console.log('- If BL Test Env shows ✅ MATCH and Reseller-1 shows ❌ NO MATCH, the logic is correct');
console.log('- If both show ✅ MATCH, then the server should prefer the one with more matching words');
console.log('- If BL Test Env shows ❌ NO MATCH, we found the bug!');
console.log('\n💡 Expected behavior:');
console.log('- BL Test Env words ["test", "env"] should match query words ["test", "env"]');
console.log('- This should result in 2 matching words ≥ min(2, 2) = true');
console.log('- Therefore BL Test Env should be selected over Reseller-1');