Skip to content

Commit

Permalink
Merge 0365019 into 1d5b619
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaong committed Apr 5, 2022
2 parents 1d5b619 + 0365019 commit 4334502
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/MiniSearch.test.js
Expand Up @@ -598,6 +598,19 @@ describe('MiniSearch', () => {
expect(combined[1].match.gentes).toEqual(['text'])
})

it('ranks prefix matches higher than fuzzy matches with the same distance, all else being equal', () => {
const ms = new MiniSearch({ fields: ['text'] })
const documents = [
{ id: 1, text: 'unicorns' },
{ id: 2, text: 'unikorn' }
]
ms.addAll(documents)
expect(ms.documentCount).toEqual(documents.length)

const results = ms.search('unicorn', { fuzzy: 0.2, prefix: true })
expect(results.map(({ id }) => id)).toEqual([1, 2])
})

it('accepts a function to compute fuzzy and prefix options from term', () => {
const fuzzy = jest.fn(term => term.length > 4 ? 2 : false)
const prefix = jest.fn(term => term.length > 4)
Expand Down
2 changes: 1 addition & 1 deletion src/MiniSearch.ts
Expand Up @@ -1396,7 +1396,7 @@ const defaultSearchOptions = {
fuzzy: false,
maxFuzzy: 6,
boost: {},
weights: { fuzzy: 0.45, prefix: 0.375 }
weights: { fuzzy: 0.4, prefix: 0.375 }
}

const defaultAutoSuggestOptions = {
Expand Down

0 comments on commit 4334502

Please sign in to comment.