Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaong committed Nov 23, 2022
1 parent 90f9a43 commit 3066d14
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/MiniSearch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,25 @@ describe('MiniSearch', () => {
expect(results.every(({ category }) => category === 'poetry')).toBe(true)
})

it('allows customizing BM25+ parameters', () => {
const ms = new MiniSearch({ fields: ['text'], searchOptions: { _bm25: { k: 1.2, b: 0.7, d: 0.5 } } })
const documents = [
{ id: 1, text: 'something very very very cool' },
{ id: 2, text: 'something cool' }
]
ms.addAll(documents)

expect(ms.search('very')[0].score).toBeGreaterThan(ms.search('very', { _bm25: { k: 1, b: 0.7, d: 0.5 } })[0].score)
expect(ms.search('something')[1].score).toBeGreaterThan(ms.search('something', { _bm25: { k: 1.2, b: 1, d: 0.5 } })[1].score)
expect(ms.search('something')[1].score).toBeGreaterThan(ms.search('something', { _bm25: { k: 1.2, b: 0.7, d: 0.1 } })[1].score)

// Defaults are taken from the searchOptions passed to the constructor
const other = new MiniSearch({ fields: ['text'], searchOptions: { _bm25: { k: 1, b: 0.7, d: 0.5 } } })
other.addAll(documents)

expect(other.search('very')).toEqual(ms.search('very', { _bm25: { k: 1, b: 0.7, d: 0.5 } }))
})

describe('when passing a query tree', () => {
it('searches according to the given combination', () => {
const results = ms.search({
Expand Down Expand Up @@ -1514,7 +1533,7 @@ describe('MiniSearch', () => {
expect(ms.search('queen', { fuzzy: 1, prefix: true })[0].song).toEqual('Killer Queen')
})
})
})
})

describe('default tokenization', () => {
it('splits on non-alphanumeric taking diacritics into account', () => {
Expand Down

0 comments on commit 3066d14

Please sign in to comment.