MCPcopy Create free account
hub / github.com/bywwcnll/StreamPanel / getFieldMatchScore

Function getFieldMatchScore

devtools/panel.bundle.js:1435–1456  ·  view source on GitHub ↗
(field, query)

Source from the content-addressed store, hash-verified

1433 }
1434
1435 function getFieldMatchScore(field, query) {
1436 const normalizedField = field.toLowerCase();
1437 const compactField = normalizedField.replace(/[._\-\s]/g, '');
1438 const compactQuery = query.replace(/[._\-\s]/g, '');
1439 const queryParts = query.split(/[.\s]+/).filter(Boolean);
1440
1441 if (normalizedField === query) return 0;
1442 if (normalizedField.startsWith(query)) return 1;
1443 if (normalizedField.includes(query)) return 2 + normalizedField.indexOf(query) / 1000;
1444 if (compactField.includes(compactQuery)) return 3 + compactField.indexOf(compactQuery) / 1000;
1445
1446 if (queryParts.length > 1 && queryParts.every(part => normalizedField.includes(part))) {
1447 return 4;
1448 }
1449
1450 const fuzzyScore = getSubsequenceScore(compactField, compactQuery);
1451 if (fuzzyScore !== Infinity) {
1452 return 5 + fuzzyScore / 1000;
1453 }
1454
1455 return Infinity;
1456 }
1457
1458 function getSubsequenceScore(text, query) {
1459 if (!query) return 0;

Callers 1

getFuzzyMatchedFieldsFunction · 0.70

Calls 1

getSubsequenceScoreFunction · 0.70

Tested by

no test coverage detected