feat: add configurable limit to search results (#1281)

* feat: add configurable limit to search results

Signed-off-by: Navendu Pottekkat <navendu@apache.org>

* 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 <navendu@apache.org>
Co-authored-by: Aditya Telange <21258296+adityatelange@users.noreply.github.com>
This commit is contained in:
Navendu Pottekkat 2023-08-12 13:17:24 +05:30 committed by GitHub
parent ac1e041419
commit f7bd1ec07c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -77,7 +77,12 @@ sInput.onkeyup = function (e) {
// run a search query (for "term") every time a letter is typed // run a search query (for "term") every time a letter is typed
// in the search box // in the search box
if (fuse) { 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) { if (results.length !== 0) {
// build our html if result exists // build our html if result exists
let resultSet = ''; // our results bucket let resultSet = ''; // our results bucket