krisk / Fuse

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

Some results seem not relevant to the search pattern #544

Closed iOliverNguyen closed 3 years ago

iOliverNguyen commented 3 years ago

Describe the bug

The results are not relevant. I searched for cmdpat and I got something like src/database at the top result. 😕

Version

6.4.6

Is this a regression?

I'm not sure

🔬Minimal Reproduction

The file go.json is the list of golang/go files from GitHub API. It can be downloaded here: gist.github.com/olvrng/cff3528c0ae32ab7081a2c56a68f7860.

The minimal reproduction script is below:

import * as fs from 'fs';
import Fuse from 'fuse.js';

const data = JSON.parse(fs.readFileSync('./go.json').toString());
console.log(data[0], data[1]); // make sure we are reading the file correctly

const fuse = new Fuse(data, {includeScore: true});
const result = fuse.search('cmdpat', {limit: 10});
console.log(result);

What I expected

I expected these lines should appear higher in the list

src/cmd/go/internal/base/path.go
src/cmd/go/internal/load/path.go
src/cmd/go/internal/str/path.go
...

What I saw instead

The results are not relevant at all 🤔

[
  { item: 'src/database', refIndex: 4246, score: 0.35333333333333333 },
  {
    item: 'src/database/sql',
    refIndex: 4247,
    score: 0.35333333333333333
  },
  {
    item: 'src/database/sql/convert.go',
    refIndex: 4248,
    score: 0.35333333333333333
  },
  {
    item: 'src/database/sql/convert_test.go',
    refIndex: 4249,
    score: 0.35333333333333333
  },
  {
    item: 'src/database/sql/ctxutil.go',
    refIndex: 4250,
    score: 0.35333333333333333
  },
  {
    item: 'src/database/sql/doc.txt',
    refIndex: 4251,
    score: 0.35333333333333333
  },
  // ...

Thank you for taking the time to write the library and consider this issue.

emmsdan commented 3 years ago

I think I have a similar issue

pattern = 'gtb'

result

[
  {
    "item": {
      "title": "Sterling Bank Plc",
      "filename": "sterling_bank"
    },
    "refIndex": 0,
    "score": 0.2388538854091851
  },
  {
    "item": {
      "title": "Guaranty Trust Bank GTB",
      "filename": "guaranty_trust_bank"
    },
    "refIndex": 1,
    "score": 0.4472135954999579
  }
]

If I set isCaseSensitive: true the second one does not even show on the list.

you can even test this on the demo page https://fusejs.io/demo.html

github-actions[bot] commented 3 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