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

Function rankSearchItems

packages/web/src/index.ts:182–201  ·  view source on GitHub ↗
(query: string)

Source from the content-addressed store, hash-verified

180}
181
182function rankSearchItems(query: string) {
183 const normalizedQuery = normalizeSearchText(query);
184 const results = searchItems
185 .map((item) => ({ item, score: scoreSearchItem(item, normalizedQuery) }))
186 .filter((result) => result.score > 0)
187 .sort((a, b) => {
188 if (b.score !== a.score) return b.score - a.score;
189 const dateComparison = compareSearchDates(
190 searchSortDate(a.item),
191 searchSortDate(b.item),
192 );
193 if (dateComparison !== 0) return dateComparison;
194 return a.item.title.localeCompare(b.item.title, undefined, {
195 numeric: true,
196 sensitivity: "base",
197 });
198 });
199
200 return normalizedQuery ? results.slice(0, 40) : results.slice(0, 18);
201}
202
203function compareSearchDates(a?: string, b?: string) {
204 if (a === undefined && b === undefined) return 0;

Callers 1

renderSearchResultsFunction · 0.85

Calls 4

normalizeSearchTextFunction · 0.85
scoreSearchItemFunction · 0.85
compareSearchDatesFunction · 0.85
searchSortDateFunction · 0.85

Tested by

no test coverage detected