(query: string)
| 180 | } |
| 181 | |
| 182 | function 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 | |
| 203 | function compareSearchDates(a?: string, b?: string) { |
| 204 | if (a === undefined && b === undefined) return 0; |
no test coverage detected