MCPcopy Create free account
hub / github.com/anomalyco/models.dev / fuzzySequenceScore

Function fuzzySequenceScore

packages/web/src/index.ts:116–138  ·  view source on GitHub ↗
(haystack: string, needle: string)

Source from the content-addressed store, hash-verified

114}
115
116function fuzzySequenceScore(haystack: string, needle: string) {
117 let score = 0;
118 let previousIndex = -1;
119 let searchFrom = 0;
120
121 for (const character of needle) {
122 const index = haystack.indexOf(character, searchFrom);
123 if (index === -1) return 0;
124
125 if (index === 0 || haystack[index - 1] === " ") {
126 score += 8;
127 } else if (index === previousIndex + 1) {
128 score += 6;
129 } else {
130 score += 2;
131 }
132
133 previousIndex = index;
134 searchFrom = index + 1;
135 }
136
137 return score + Math.max(0, 12 - haystack.length / 8);
138}
139
140function scoreTerm(field: string, term: string) {
141 const normalized = normalizeSearchText(field);

Callers 1

scoreTermFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected