Skip to content

Commit

Permalink
feat: add configurable limit to search results (adityatelange#1281)
Browse files Browse the repository at this point in the history
* feat: add configurable limit to search results

Signed-off-by: Navendu Pottekkat <[email protected]>

* 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 <[email protected]>
Co-authored-by: Aditya Telange <[email protected]>
  • Loading branch information
2 people authored and Sudhir S committed Jan 24, 2024
1 parent 108370a commit e335597
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion assets/js/fastsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e335597

Please sign in to comment.