c4milo / fusejs

Low level fuse bindings for nodejs
http://c4milo.github.io/fusejs
112 stars 72 forks source link

Returned scores for certain search terms are equal when differences exist beyond the length of the search query. #39

Closed RoderickJDunn closed 4 years ago

RoderickJDunn commented 4 years ago

Consider this very basic example to illustrate what I mean.

List of Items to search through:

let list = [
"mr. h",
"mr. p",
"mr. m"
];

Search Term: let searchTerm = "mr.h"

Notice that the search term is almost equivalent to the first result- the only difference is the missing space after the ".".

Running the search produces the following results:

const options = {
  includeScore: false,
  threshold: 0.7,
};

const fuse = new Fuse(list, options)
const result = fuse.search(searchTerm)

[ { "item": "mr. h", "refIndex": 0, "score": 0.37526977437859277 }, { "item": "mr. p", "refIndex": 1, "score": 0.37526977437859277 }, { "item": "mr. m", "refIndex": 2, "score": 0.37526977437859277 } ]

I would expect the first item "mr. h" to have a higher score than the other 2, since it has only 1 character difference compared to the search query, while the others have two differences. However, all 3 scores are equal.

This behaviour only seems to be present when the list items are longer than the search query, and are identical up to the length of the search query, but have differences beyond that.

Is this expected behaviour? If so, could you explain why that's the case?