I'm using normalizr to get an object with the ids as keys, so I can access specific items without iterating every time through the array.
I've seen that fuse can be configured to return only the results ids, which is nice for my purpose. But then it does not take my nested object.
Example:
const collection = {
135 : {
name : 'foo',
_id : 135
},
187 : {
name : 'bar',
_id : 187
}
}
the search always returns an empty array :(
Fuse doesn't do that out of the box. However, couldn't you just transform the object into an array, then pass that to Fuse? Something like:
const collection = {
135 : {
name : 'foo',
_id : 135
},
187 : {
name : 'bar',
_id : 187
}
}
var items = Object.keys(collection).map(function (key) {
return collection[key];
});
// items is now: [{"name":"foo","_id":135},{"name":"bar","_id":187}]
var fuse = new Fuse(items)
// etc...
sure, thats how i do it now. i hoped it would work without the loop :(
Thanks anyways. Cool lib btw.
Thanks @Artem-Schander :smiley:
Thinking more about this, it might worth implementing in the core lib.
that would be really nice.
I'll fork it later. Maybe I can help :)
added support for said objects in root level
Somewhat relevant:
var list = [
{title: "Old Man's War" },
{title: "The Lock Artist"},
{title: "The Code of the Wooster"}
]
var options = {
id: "title", // <-- option to return array indexes
keys: [ "title"]
};
var fuse = new Fuse(list, options);
var result = fuse.search("the");
console.log(result) // --> ["The Lock Artist", "The Code of the Wooster"]
Is there an option to return indexes of items in the array?
so that
```javascript
console.log(result) // --> [1, 2]
I feel like this and numerous other issues should be closed as they are outdated 馃
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
Most helpful comment
Thanks @Artem-Schander :smiley:
Thinking more about this, it might worth implementing in the core lib.