-
-
Notifications
You must be signed in to change notification settings - Fork 772
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
Dots in object key names are misrepresented and treated as nested values #432
Comments
Yes, I think it's a good solution. That way it'll serve double duty even for string-based dot-delimited paths. For example: const list = [
{
title: 'HTML5',
author: {
firstName: 'Remy',
lastName: 'Sharp'
}
},
{
title: 'Angels & Demons',
author: {
firstName: 'Dan',
lastName: 'Brown'
}
}
]
const fuse = new Fuse(list, {
// this is the same as `['title', 'author.firstName']`
keys: ['title', ['author', 'firstName']]
}) And, as per your example: const options = {
keys: ['id', ['http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'value']],
}; The one tricky part is how this API should look like for logical query operators, since right now it looks like this: const result = fuse1.search({
$and: [{ 'author.firstName': 'dn' }, { 'author.lastName': 'bron' }]
}) However, if we were to also allow arrays as keys, then I'd have to rethink its API. One potential design could be the following: const result = fuse.search({
$and: [
{
$path: ['author', 'firstName'],
$query: 'dn'
},
{
$path: ['author', 'lastName'],
$query: 'bron'
}
]
}) Admittedly, this looks quite unpleasant. Thoughts? |
Good observation. The only other way I can think of to keep the API minimal and similar to the const result = fuse1.search({
$and: [
{
"[ 'author', 'firstName' ]": 'dn'
}
]
}) And then parse the key. E.g. you could parse them with Although this solution is syntactically closer to the |
Describe the bug
If you want to search into nested objects, the keys of that object cannot contain dots, otherwise when specifying Fuse options they will be treated as nested values. In my case, every key is a url and the dots cannot be avoided.
Version
v6.0.2
Is this a regression?
No
🔬Minimal Reproduction
Have a list of objects such as:
You want to search for
value
insidehttp://www.w3.org/1999/02/22-rdf-syntax-ns#type
, so you define an options object:Since nested objects are indicated with a dot, Fuse treats e.g.
w3
as a key contained in the objecthttp://www
.Additional context
It could be solved by using e.g. optional nested arrays for such values:
The text was updated successfully, but these errors were encountered: