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

Function scoreTerm

packages/web/src/index.ts:140–151  ·  view source on GitHub ↗
(field: string, term: string)

Source from the content-addressed store, hash-verified

138}
139
140function scoreTerm(field: string, term: string) {
141 const normalized = normalizeSearchText(field);
142 if (!normalized) return 0;
143 if (normalized === term) return 120;
144 if (normalized.startsWith(term)) return 100;
145 if (normalized.split(" ").some((word) => word.startsWith(term))) return 82;
146
147 const index = normalized.indexOf(term);
148 if (index !== -1) return 64 - Math.min(index, 24);
149
150 return fuzzySequenceScore(normalized, term);
151}
152
153function scoreSearchItem(item: SearchIndexItem, query: string) {
154 const terms = normalizeSearchText(query).split(/\s+/).filter(Boolean);

Callers 1

scoreSearchItemFunction · 0.85

Calls 2

normalizeSearchTextFunction · 0.85
fuzzySequenceScoreFunction · 0.85

Tested by

no test coverage detected