lucaong / minisearch

Tiny and powerful JavaScript full-text search engine for browser and Node
https://lucaong.github.io/minisearch/
MIT License
4.81k stars 137 forks source link

Two character searches always come back blank #189

Closed divmgl closed 1 year ago

divmgl commented 1 year ago

Not much to say here. In two distinct datasets, searching with two characters using fuzzy searching >= 1 will always return an empty array.

divmgl commented 1 year ago

Switching prefix to true seems to make it work as intended.

lucaong commented 1 year ago

Hi @divmgl , Thanks for reporting this, but I cannot reproduce it. In fact, if I try a simple demo, things work properly:

const ms = new MiniSearch({ fields: ['txt'] })
const docs = [{ id: 1, txt: 'f' }, { id: 2, txt: 'fo' }, { id: 3, txt: 'foo' }, { id: 4, txt: 'fox' }]
ms.addAll(docs)
ms.search('fo', { fuzzy: 2 })
/* =>
[
  {
    id: 2,
    score: 1.8059592064889043,
    terms: [ 'fo' ],
    match: { fo: [Array] }
  },
  {
    id: 3,
    score: 0.6095112321900052,
    terms: [ 'foo' ],
    match: { foo: [Array] }
  },
  {
    id: 4,
    score: 0.6095112321900052,
    terms: [ 'fox' ],
    match: { fox: [Array] }
  },
  {
    id: 1,
    score: 0.4063408214600035,
    terms: [ 'f' ],
    match: { f: [Array] }
  }
]
*/

Could you please provide some example code?

lucaong commented 1 year ago

Closing this because I cannot reproduce it, and I suspect it is an application issue, but I am happy to reopen it if some reproduction is provided @divmgl

divmgl commented 1 year ago

Here's the repro.

https://stackblitz.com/edit/node-o22erp?file=index.js

Is it user error?

divmgl commented 1 year ago

~Yeah, disregard. It's user error. Thanks.~

~Actually, it seems to happen with bigger datasets. But alas, I can't copy the entire data set onto the public repro. No worries.~

Nope, I'm definitely wrong and it was user error. Thanks.

lucaong commented 1 year ago

Thanks @divmgl for replying :)