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

Mixing fuzzy and exact search #408

Closed
jnsprnw opened this issue Apr 29, 2020 · 4 comments
Closed

Mixing fuzzy and exact search #408

jnsprnw opened this issue Apr 29, 2020 · 4 comments

Comments

@jnsprnw
Copy link

jnsprnw commented Apr 29, 2020

Let’s say I have the following array:

[
  {
    "title": "Old Man's War",
    "color": "red"
  },
  {
    "title": "The Lock Artist",
    "color": "red"
  },
  {
    "title": "HTML5",
    "color": "blue"
  }
]

The user can type a term for fuzzy searching within the title, but also a dropdown to select the exact color.
Should I filter the array by color; create a new Fuse instance with the filtered array; and then do the fuzzy search? Not sure if that’s the best thing performance-wise if I do that every time a new color is selected from the dropdown.

Having an API to add/remove items as suggested in #379 might be useful.

@krisk
Copy link
Owner

krisk commented May 3, 2020

As per #411, I'm actually working on logical query expressions, such that you can search like this:

const result = fuse.search({
  $and: [{ author: 'abc' }, { title: 'xyz' }]
})
const result = fuse.search({
  $and: [{ author: 'abc' }, { $or: [{ title: 'nonfic' }, { title: 'html' }] }]
})

From there, you can then mix it with extended searching so you could do exact-match for color:

const result = fuse.search({
  $and: [
    { title: 'old war' }, // fuzzy "old war"
    { color: "'blue"} // exact match for blue
  ]
})

@krisk krisk added the feature label May 3, 2020
@krisk krisk added this to the v6.0.0 milestone May 3, 2020
@krisk krisk closed this as completed May 13, 2020
@jnsprnw
Copy link
Author

jnsprnw commented Jul 16, 2020

Hey hey,
sorry for using this old issue again. I’m trying to figure out if it’s possible to mix expressions and search terms in the logical query operators you’ve implemented. Something like this:

const result = fuse.search({
  $and: [
    'old war', // fuzzy "old war" in all keys
    { color: "'blue"} // exact match for blue
  ]
})

My goal is to not only search for old war in the title key but in all keys (maybe except color). The code above does not generate any errors, but still does not return any results.

Thanks so much!

@JamesBliss
Copy link

@jnsprnw Did you end up figuring this out? I've come up against the same need/want.

@jnsprnw
Copy link
Author

jnsprnw commented Feb 15, 2023

Unfortunately not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants