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

Match indices contain ranges of partial matches #611

Closed
codeaid opened this issue Jan 24, 2022 · 4 comments
Closed

Match indices contain ranges of partial matches #611

codeaid opened this issue Jan 24, 2022 · 4 comments

Comments

@codeaid
Copy link

codeaid commented Jan 24, 2022

Describe the bug

When including matches in the results the indices array contains ranges of partial matches that shouldn't be included in the output.

Version

v6.5.3

Is this a regression?

I don't think it is as there is another report from two years ago about the same issue (#505) that was automatically closed and never resolved.

🔬Minimal Reproduction

const data = [
  { value: 'AA BB AAA BBB' },
];

const index = new Fuse(data, {
  includeMatches: true,
  ignoreFieldNorm: true,
  ignoreLocation: true,
  includeScore: true,
  keys: ['value'],
  threshold: 0.001,
});

const results = index.search('AAA');

After this results contains the following:

[
  {
    "item": {
      "value": "AA BB AAA BBB"
    },
    "refIndex": 0,
    "matches": [
      {
        "indices": [
          [ 0, 1 ],
          [ 6, 8 ]
        ],
        "value": "AA BB AAA BBB",
        "key": "value"
      }
    ],
    "score": 0.001
  }
]

Note how indices contains [0, 1] when it's not even a match. I'm guessing it's there because it's a partial match, however, there aren't any options available to get rid of it. Event the threshold of 0.001 seems to be completely ignored.

This behaviour renders the indices pretty much useless because they include irrelevant ranges, which I as someone in this case searching for AAA don't even care about.

The suggestion to set minMatchCharLength to 2 (mentioned in #505) is not really a solution because it would still behave in the exact same way scenarios like this when the irrelevant match is 2 or more characters long.

Additional context

I wanted to use this functionality to highlight matches in search results but as it stands it's not possible because if the user searches for AAA and I'm not manually processing/filtering indices in any way then AA would also get highlighted confusing the user.

Not knowing much about internals of this library I'd suggest to either completely remove indices or matches that are not full matches, or at least respect the threshold and not include indices that don't match the threshold.

@codeaid codeaid added the bug label Jan 24, 2022
@codeaid
Copy link
Author

codeaid commented Feb 3, 2022

I've been experimenting with highlighting search results and just stumbled upon another good example.

When having an indexed string value of 402220 63193795 0000 ABC and searching for 402220 the following indices are returned:

  • 0, 5
  • 16, 19

As a result I end up highlighting 402220 and 0000, which is obviously completely wrong because the search query doesn't even contain two zeroes, let alone four.

Same happens even if I enable the useExtendedSearch flag and wrap my query in double quotes ("402220"), thinking that it will only return exact matches.

@github-actions
Copy link

github-actions bot commented Mar 6, 2022

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

@zach-is-my-name
Copy link

Yeah same problem

@sunknudsen
Copy link

sunknudsen commented Jan 11, 2023

@krisk Would you happen to know what is going on? Experiencing similar issue… see screenshot.

import fuseJs from "fuse.js"



const faqFuseJs = new fuseJs(sortableTopics, {
  distance: Infinity,
  findAllMatches: true,
  includeMatches: true,
  keys: ["content", "metadata.title"],
  minMatchCharLength: 2,
  shouldSort: true,
  threshold: 0,
})

const results = faqFuseJs.search("linux")

console.log(results)

I am perhaps naively expecting indices to contain a single linux match… puzzled.

fuse

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