krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
18.39k stars 772 forks source link

Ignore accents #181

Closed MatthiasRMS closed 4 years ago

MatthiasRMS commented 7 years ago

Is there an option to ignore accents ? Example:

items: [{name: "Référence"}, {name: "Dénomination}]

If I search for reference, it won't find Référence

Is this already possible?

Nb: it does work if you only have those two options, but with a large amount, it doesn't.

robozevel commented 7 years ago

I'd recommend adding an extra key, and using speakingurl to normalize it (remove diacritics and such)

const getSlug = require('speakingurl')
// returns "Schoener Titel laesst gruessen!? Bel ete !"
let normalized = getSlug('Schöner Titel läßt grüßen!? Bel été !', {
  separator: ' ',
  mark: true,
  uric: true,
  uricNoSlash: true,
  maintainCase: true
})
MatthiasRMS commented 7 years ago

@robozevel thanks for the advice, I can indeed to this! However, wouldn't it be nice to have this built in ?

I'd be happy to work on this and make a PR. @krisk would you accept a PR to add an option ignoring diacritics ?

ejames17 commented 6 years ago

actually an option to ignore any pattern would be super awesome as well

omarciovsena commented 6 years ago

I solved this:

const removeSpecialCharacters = str => {
  return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '')
}
const list = suggestions.map(suggestion => ({
  value: suggestion.value,
  noSpecialCharacters: removeSpecialCharacters(suggestion.value)
}))

let opts = {
  keys: ['value', 'noSpecialCharacters']
  ...
}

but I agree it could be a parameter. I will try to contribute to this if it is in your interest.

Startouf commented 5 years ago

Definitely interesting to cover many languages. The default should be to not be accent-insensitive through to not introduce breaking changes

github-actions[bot] commented 4 years ago

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