1
0
mirror of https://github.com/ryanoasis/nerd-fonts.git synced 2024-12-19 20:12:52 +02:00

cheat-sheet: Sort the results

[why]
Often it is easier to find what one wants if the search result is
sorted.

[how]
Do a full result sort.
* Sort by id (class name)
* Put removed icons last

We do not need the boost function anymore, so that pre-sorting is
removed.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
Fini Jastrow 2023-05-30 13:33:09 +02:00
parent b42a1b82e6
commit b068b08653

View File

@ -9,7 +9,7 @@ document.addEventListener('DOMContentLoaded', function () {
// Index all glyphs/icons
let miniSearch = new MiniSearch({
fields: ['id', 'code', 'isNew'], // fields to index for full-text search
fields: ['id', 'code'], // fields to index for full-text search
storeFields: ['id', 'code', 'isRemoved'], // fields to return with search results
})
miniSearch.addAll(Object.entries(glyphs).map(
@ -17,7 +17,7 @@ document.addEventListener('DOMContentLoaded', function () {
return {
id: key,
code: value,
isNew: key.startsWith('nfold') ? false : key,
isRemoved: key.startsWith('nfold'),
}
}
));
@ -130,15 +130,18 @@ document.addEventListener('DOMContentLoaded', function () {
// TODO: search suggestions
// TODO: show removed/deprecated icons at the end of results list.
remainingSearchResults = miniSearch.search(searchTerm,
{
prefix: true,
combineWith: "AND",
boost: { isNew: 2 },
}
);
remainingSearchResults.sort((a, b) => {
if (a.isRemoved != b.isRemoved) {
return a.isRemoved > b.isRemoved
}
return a.id > b.id
})
console.log(`search: ${remainingSearchResults.length} results found`);
elementGlyphCheatSheet.replaceChildren([]);