Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

limit search results in fuse.js vue

I've implemented fuse.js with this guide : https://fusejs.io/ and the code :

const Fuse = require("fuse.js");
  var fuse = new Fuse(this.$store.state.vendorProducts, options); 
  var result = fuse.search(this.itemTitle);

the result variable includes all the results of search operation.
I want just first 20 results from result. I can slice the result array, but its too slow, because its loaded all data.
How can i limit the search results by for example first 20 items?

like image 329
mmarket Avatar asked Nov 03 '25 02:11

mmarket


1 Answers

Fuse search has search SearchOpts that has only param limit so

const Fuse = require("fuse.js");
  var fuse = new Fuse(this.$store.state.vendorProducts, options); 
  var result = fuse.search(this.itemTitle, {limit: 20});

Found this feature from looking into source code.

like image 114
Innar Hallik Avatar answered Nov 05 '25 23:11

Innar Hallik