Closed tesla-cat closed 3 years ago
it is not efficient to access the entire doc collection when it is large
I use index only, without accessing the entire collection
const Fuse = require('fuse.js') const options = { keys: ['title'] } function updateIndex(oldIndex, newDoc){ if(oldIndex){ const myIndex = Fuse.parseIndex(oldIndex) const fuse = new Fuse([], options, myIndex) fuse.add(newDoc) return fuse.getIndex() } else{ return Fuse.createIndex(['title'], [newDoc]) } } const idx1 = updateIndex(null, { title: 'hello', id: 'id1' }) console.log(idx1.size()) const idx2 = updateIndex(idx1, { title: 'world', id: 'id2' }) console.log(idx2.size()) const fuse = new Fuse([], options, idx2) console.log(fuse.search('hel')) console.log(fuse.search('wor')) console.log(fuse.search('hello world'))
this works but I only get its number index
1 2 [ { item: undefined, refIndex: 0 } ] [ { item: undefined, refIndex: 1 } ] [ { item: undefined, refIndex: 0 }, { item: undefined, refIndex: 1 } ]
how can I get id1, id2 instead of the numbers 0, 1
id1, id2
0, 1
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days
motivation
it is not efficient to access the entire doc collection when it is large
code
I use index only, without accessing the entire collection
result
this works but I only get its number index
question
how can I get
id1, id2
instead of the numbers0, 1