Skip to content
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

search in nested array #47

Closed
fraserxu opened this issue Mar 6, 2015 · 2 comments
Closed

search in nested array #47

fraserxu opened this issue Mar 6, 2015 · 2 comments
Labels

Comments

@fraserxu
Copy link

fraserxu commented Mar 6, 2015

I have a nested object like this:

[
  {
    name: 'levelA',
    number: 12341,
    district: [
      {
        name: 'levelB',
        number: 12341,
        township: [
          {
            name: 'levelC',
            number: 12341,
            tv: [
              {
                name: 'levelD',
                number: 12341
              }
            ]
          }
        ]
      }
    ]
  },
  {
    name: 'levelA2',
    number: 12341,
    district: [
      {
        name: 'levelB2',
        number: 12341,
        township: [
          {
            name: 'levelC2',
            number: 12341,
            tv: [
              {
                name: 'levelD2',
                number: 12341
              }
            ]
          }
        ]
      }
    ]
  }
]

I want to filter the result by name at all levels so I write the search like this:

let fuse = new Fuse(data, {
  keys: ['name']
});
fuse.search(keywords);

But this only return me the result in the first level of name. I'm not sure how to index the name in the second or deeper level because it's not an object.

Maybe something like this keys: ['name', 'district.name']?

@krisk Any ideas? Thanks.

@krisk krisk added the question label Mar 31, 2015
@DemersM
Copy link

DemersM commented May 8, 2015

+1 for this

@jeancroy
Copy link

jeancroy commented Jul 3, 2015

something like this should work:
keys: ['name', 'district.name','district.township.name','district.township.tv.name']

@krisk krisk closed this as completed Feb 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants