Closed wongmrdev closed 4 years ago
no search produces sample code in JS. And the documentation only has a typescript example.
I've updated the docs for createIndex
Hi Krisk, Really appreciate this! I was wondering if I had to put the data type in an array and pass that to the createIndex function, I was really confused! thanks for the JS version!
in case it helps anyone, if you want to pre-build the index this worked for me:
const options = { keys: ['title', 'author.firstName'] }
// Create the Fuse index
const myIndex = Fuse.createIndex(options.keys, books)
// Serialize and save the Fuse index
fs.writeFileSync('fuse-index.json', JSON.stringify(myIndex.toJSON()));
// require/fetch the index somehow
const fuseIndex = await require('/assets/fuse-index.json');
// initialize Fuse
const fuse = new Fuse(books, options, Fuse.parseIndex(searchIndex))
disclaimer: I'm not sure if this is officially supported or even the right way to do it!
This is right way to do it, and officially supported.
I am little confuse why we need again books as first parameter.becuase we already created index file using books varaible.if i am using only searchIndex with pass books this is not working // require/fetch the index somehow const fuseIndex = await require('/assets/fuse-index.json'); // initialize Fuse const fuse = new Fuse(books, options, Fuse.parseIndex(searchIndex))
Hi, I'm trying to implement the index search for Fuse, but for some reason it's not working. My error is