Skip to content

Commit

Permalink
cheat-sheet: Sort the results
Browse files Browse the repository at this point in the history
[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>
  • Loading branch information
Finii committed May 30, 2023
1 parent c0186f7 commit 9d09f38
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cheat-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ 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(
([key, value]) => {
return {
id: key,
code: value,
isNew: key.startsWith('nfold') ? false : key,
isRemoved: key.startsWith('nfold'),
}
}
));
Expand Down Expand Up @@ -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([]);
Expand Down

0 comments on commit 9d09f38

Please sign in to comment.