From f7bd1ec07cdbfe9951fdec4e0c03e39ef7bd40d1 Mon Sep 17 00:00:00 2001 From: Navendu Pottekkat Date: Sat, 12 Aug 2023 13:17:24 +0530 Subject: [PATCH] feat: add configurable limit to search results (#1281) * feat: add configurable limit to search results Signed-off-by: Navendu Pottekkat * Handle case where params.fuseOpts is not defined resulting into `Cannot read properties of null (reading 'limit')` Utilizes search options by fuse https://www.fusejs.io/api/methods.html#search The options: limit (type: number): Denotes the max number of returned search results. --------- Signed-off-by: Navendu Pottekkat Co-authored-by: Aditya Telange <21258296+adityatelange@users.noreply.github.com> --- assets/js/fastsearch.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/assets/js/fastsearch.js b/assets/js/fastsearch.js index 06ebcfba..9484e751 100644 --- a/assets/js/fastsearch.js +++ b/assets/js/fastsearch.js @@ -77,7 +77,12 @@ sInput.onkeyup = function (e) { // run a search query (for "term") every time a letter is typed // in the search box if (fuse) { - const results = fuse.search(this.value.trim()); // the actual query being run using fuse.js + let results; + if (params.fuseOpts) { + results = fuse.search(this.value.trim(), {limit: params.fuseOpts.limit}); // the actual query being run using fuse.js along with options + } else { + results = fuse.search(this.value.trim()); // the actual query being run using fuse.js + } if (results.length !== 0) { // build our html if result exists let resultSet = ''; // our results bucket