krisk / Fuse

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

Not really relevant? #237

Closed jaschaio closed 4 years ago

jaschaio commented 6 years ago

I have just been playing with the Demo on http://fusejs.io/ and it seems to me that it doesn't really work well.

These are my options:

var options = {
  shouldSort: true,
  includeScore: true,
  threshold: 0.6,
  location: 0,
  distance: 100,
  maxPatternLength: 32,
  minMatchCharLength: 2,
  keys: [
    "title",
    "author.firstName",
    "author.lastName"
]
};
var fuse = new Fuse(list, options); // "list" is the item array
var result = fuse.search("steve");

These are my results:

[
  {
    "item": {
      "title": "The Lock Artist",
      "author": {
        "firstName": "Steve",
        "lastName": "Hamilton"
      }
    },
    "score": 0.3
  },
  {
    "item": {
      "title": "Monster 1959",
      "author": {
        "firstName": "David",
        "lastName": "Maine"
      }
    },
    "score": 0.43000000000000005
  },
  {
    "item": {
      "title": "Right Ho Jeeves",
      "author": {
        "firstName": "P.D",
        "lastName": "Woodhouse"
      }
    },
    "score": 0.49
  },
  {
    "item": {
      "title": "Thank You Jeeves",
      "author": {
        "firstName": "P.D",
        "lastName": "Woodhouse"
      }
    },
    "score": 0.5
  }
  // […] more results, cut for brevity - you can check it out yourself on the demo page

I don't see why all those results should return when I am searching for steve. Yes, the second result with a score of 0.43 matches Mon*ste*r part of it, but not the whole word. If this were the results list for a real search I wouldn't be happy.

I would expect only to find one results which exactly matches the given term. If I just search vor ste than I would understand why it returns the other results.

How would I got about this in a real application? Playing with the treshold doesn't seem reliable enough. Maybe I have to set the minMatchCharLength to the same lenght as my search string, but this still gives me very similar results.

Would be really grateful if someone explains to me what I am overlooking.

Thanks!

krisk commented 6 years ago

@jaschaio

I would expect only to find one results which exactly matches the given term. If I just search for ste than I would understand why it returns the other results.

and

I would expect only to find one results which exactly matches the given term

What you're looking for is a simple substring or regex based searching. There's no need for a library, in this case.

Note that Fuse is an Approximate string matching library. That is, it measures closeness, not exactness.

When measuring closeness, you will inevitably get results which appear to have little do with the search query. However, that is a byproduct of the matching configuration, which you can tweak by altering the location, threshold, and distance options.

If you wanted to further filter the results, you can simply omit from the returned list any results whose score is not "good" enough, which is wholly subjective.

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