improve search results

pull/706/head
Cory LaViska 2022-03-15 08:56:08 -04:00
rodzic 1c903f4d26
commit 87d1db760f
1 zmienionych plików z 2 dodań i 2 usunięć

Wyświetl plik

@ -219,11 +219,11 @@
await searchIndex;
const hasQuery = query.length > 0;
const searchQuery = query
const searchTokens = query
.split(' ')
.map((term, index, arr) => `${term}${index === arr.length - 1 ? `* ${term}~1` : '~1'}`)
.join(' ');
const matches = hasQuery ? searchIndex.search(searchQuery) : [];
const matches = hasQuery ? searchIndex.search(`${query} ${searchTokens}`) : [];
const hasResults = hasQuery && matches.length > 0;
siteSearch.classList.toggle('site-search--has-results', hasQuery && hasResults);
siteSearch.classList.toggle('site-search--no-results', hasQuery && !hasResults);