farzher / fuzzysort

Fast SublimeText-like fuzzy search for JavaScript.
https://rawgit.com/farzher/fuzzysort/master/test/test.html
MIT License
3.96k stars 159 forks source link

When searching for a name containing special character, no match is found #122

Closed mannaste closed 5 months ago

mannaste commented 1 year ago

Hello!

First of all, thank you for a great library.

We have stumbled into a case where searching for one specific name containing special character, does not return a match. For example:

const targets = [
"Änni ÄÄsma",
"Anni Aasma" 
];

fuzzysort.go("Aasma", targets, { allowTypo: false }).filter(({ _indexes }) => isConsequtive(_indexes)) Result:

 [object Array] (1)
 [object Object] 
 {
  "target": "Anni Aasma",
  "_targetLower": "anni aasma",
  "_targetLowerCodes": [97, 110, 110, 105, 32, 97, 97, 115, 109, 97],
  "_nextBeginningIndexes": [4, 4, 4, 4, 5, 10, 10, 10, 10, 10],
  "_bitflags": 274689,
  "score": -5.007396449704142,
 "_indexes": [ 5, 6, 7, 8, 9 ],

fuzzysort.go("Ääsma", targets, { allowTypo: false }).filter(({ _indexes }) => isConsequtive(_indexes)) Result:

// [object Array] (0)
[]

For "Aasma" indexes are consequtive [5,6,7,8,8], but for "Ääsma", it's [0,5,7,8,9].

It would be of great help, if you happened to have any advice on how I could get the result when searching for a name with special characters ("Ääsma")?

For better visualization: https://codepen.io/mnste/pen/bGmaqpj

Thanks in advance!

ww-wolt commented 7 months ago

One workaround I found is normalizing all letters in the array as well as in the query to latin letters using the deburr function from lodash.

However you loose a little bit of sorting precision with this approach as it can not differentiate between for example "décor" and "decor" anymore.