Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not return partial matches for threshold 0 #766

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/search/bitap/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default function search(
let currentLocation = j - 1
let charMatch = patternAlphabet[text.charAt(currentLocation)]

if (computeMatches) {
if (computeMatches && threshold !== 0) {
// Speed up: quick bool to int conversion (i.e, `charMatch ? 1 : 0`)
matchMask[currentLocation] = +!!charMatch
}
Expand Down
28 changes: 28 additions & 0 deletions test/fuzzy-search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,34 @@ describe('Searching with minCharLength', () => {
})
})

describe('Searching with threshold 0', () => {
const customList = ['t te tes test tes te t']
let fuse

beforeEach(
() =>
(fuse = new Fuse(customList, {
includeMatches: true,
threshold: 0,
ignoreLocation: true,
}))
)

describe('When searching for the term "test"', () => {
let result
beforeEach(() => (result = fuse.search('test')))

test('We get a match containing 1 indices', () => {
expect(result[0].matches[0].indices).toHaveLength(1)
})

test('and the matching index is a exact match', () => {
expect(result[0].matches[0].indices[0][0]).toBe(9)
expect(result[0].matches[0].indices[0][1]).toBe(12)
})
})
})

describe('Searching with minCharLength and pattern larger than machine word size', () => {
const customList = [
'Apple pie is a tasty treat that is always best made by mom! But we love store bought too.',
Expand Down