Search does not include arrays
Closed this issue · 3 comments
If you have a Resource
that has properties in the form of an Array
, you cannot perform a collection.findOne()
or collection.findAll()
on it. It will simply return an empty Array
as the result.
Say you have a Resource
that has a tags
property, which is an Array
of said tags, you might want to use findOne()
or findAll()
to find all the resources that match a given tag.
1:
id: 1
name: Heineken
tags:
- hoofdpijn
- bagger
2:
id: 2
name: Grolsch
tags:
- bagger
3:
id: 3
name: Jupiler
tags:
- lekker
- belgisch
beers.addIndex('tags');
beers.findOne('tags', 'belgisch'); // returns []
beers.findOne('tags', 'hoofdpijn'); // returns []
beers.findAll('tags', 'bagger'); // returns []
I like your tags :) The problem with this is that the index very much behaves like an ===
comparison. What you pass in, is what you get out. So if you index ['lekker, 'belgisch']
, you would have to pass not just an identical array to match the original, but the exact reference to the array you indexed the resource with (in other words: pretty much useless).
Changing the implementation to support arrays as you suggest, seems very painful for performance (which goes counter to what we expect from an index). It may be easier in your case to keep a tag lookup map elsewhere (close to your persistence layer for example). Let me know if that poses serious challenges.
Joost, can I close this issue? (if I've answered your question to your satisfaction)
I found a way around this, so you can close this issue. Thanks!