krisk / Fuse

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

Text in Object value is not found in some wired cases #464

Closed effem closed 4 years ago

effem commented 4 years ago

Describe the bug

This happened when I tried to search for a word in multiple objects. All of the objects contained the key body which contains markdown text. In some of the field the word is found in other cases it is not. I guess it has to do something with the special characters used in markdown. It can be best seen in my example down below!

Version

Fuse: 6.4.0 Node Version: 12.16.1 Same result in Firefox: 78

Is this a regression?

Stumbled up on this the first time

🔬Minimal Reproduction

const Fuse = require('fuse.js');

const data = [{
    "title": "Title 1",
    "body": "# 111111 \n bla \n \n asdf\n \n asdf\nThis will be found",

}, {
    "title": "Title 2",
    body: "# 22222 2\n- [x] asdf\n- [x] asdf\n- [x] 123ed\n\t- [ ] asdf\n\t- [ ] asdf\n\t\t- [ ] asdf\n\t\t\t- [ ] asdf\n\n- asdf\n- asdf\n- asdf\n\nasdf\n\nasdf\n\nThis will not be found",
}, {
    "title": "Title 3",
    "body": "# 33333 \n bla blupp asdf asdf asdf\n \n asdf\n asdf",
}]

const fuse = new Fuse(data, {
    keys: [
        'title',
        'body',
    ]
});

console.log(fuse.search('found'));

Result:

$ node index.js
[
  {
    item: {
      title: 'Title 1',
      body: '# 111111 \n bla \n \n asdf\n \n asdf\nThis will be found'
    },
    refIndex: 0
  }
]

Expected At least that the second object is also found since ther word found is also present in its body

Additional context

The content of the body field looks so strange since its markdown. My guess is that this is the cause of the problem but i was not able to narrow it down to a smaller example for the second object!

krisk commented 4 years ago

Not a bug. Please read the scoring theory to understand why this is happening 😄