From b068b08653e3a292e60e5185ee4b1dc8834c4b91 Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Tue, 30 May 2023 13:33:09 +0200 Subject: [PATCH] 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 --- cheat-sheet.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cheat-sheet.js b/cheat-sheet.js index 805e8903e..5866f12a7 100644 --- a/cheat-sheet.js +++ b/cheat-sheet.js @@ -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([]);