6

Using http://fusejs.io/

In just about all situations, I'm finding that the 'indices returned contain pretty much the entire string.

For a very simple example, if you go to fusejs.io, and change the first object (in 'step 1' on the left) to

 {
    title: "so ummmmmm Old Man's War is a book about a thing",
    author: {
      firstName: "John",
      lastName: "Scalzi"
    }
 },

then tick 'Include matches' (in 'step 2' in the middle)

the resulting indices matches most of the strong, including parts that are obviously way off:

"matches": [
  {
    "indices": [
      [
        0,
        0
      ],
      [
        2,
        2
      ],
      [
        4,
        10
      ],
      [
        14,
        23
      ]
    ],
    "value": "so ummmmmm Old Man's War is a book about a thing",
    "key": "title",
    "arrayIndex": 0
  }
]

whereas I'm expecting it to just return the matched part of the string, like so:

"matches": [
  {
    "indices": [
      [
        14,
        23
      ]
    ],
    "value": "Man's War",
    "key": "title",
    "arrayIndex": 0
  }
]

I've tried it in my own app and seeing similar results across a large dataset. The matching itself is quite accurate - it's just the highlighting via matches[i].indices that's wrong. It seems to always match up to the matched string, and also sometimes far beyond. Am I going bonkers? Or is this just not possible with fuse.js?

Thanks!

P.S. Can someone please let me know if I'm supposed to include or not include the 'javascript' tag on a library question like this?

jameslol
  • 1,829
  • 16
  • 18
  • Fuse does fuzzy matching, so even matching a few characters, even just one, of the search string, is returned as a partial match. – Stobor Jul 30 '18 at 04:53
  • 1
    Indeed, I'm using Fuse because it does fuzzy matching. I'm referring to the library's particular feature of providing indices of matches inside the string. If they're going to just match everything, then what's the point? The stated reason for the indices is to highlight the matched words. Perhaps the indices could each have their own accuracy score, like there is for overall? – jameslol Jul 31 '18 at 01:12
  • I am not sure if it defeats the fuzziness feature, but if you say search for "war" and set `minMatchCharLength` to 3, you will get 3 hits with indices that would highlight exactly the substring `war`. – Ted P Oct 19 '21 at 23:00

0 Answers0