-
-
Notifications
You must be signed in to change notification settings - Fork 780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use createIndex in Javascript? #419
Comments
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 |
Hi, I'm trying to implement the index search for Fuse, but for some reason it's not working.
My error is
The text was updated successfully, but these errors were encountered: