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(logical): fix scoring for logical OR #593

Closed
Closed
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: 0 additions & 2 deletions dist/fuse.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2085,8 +2085,6 @@ var Fuse = /*#__PURE__*/function () {

if (_result.length) {
_res.push.apply(_res, _toConsumableArray(_result));

break;
}
}

Expand Down
2 changes: 2 additions & 0 deletions dist/fuse.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,6 @@ declare namespace Fuse {
}
| { $and?: Expression[] }
| { $or?: Expression[] }

export const config: Required<IFuseOptions<any>>;
}
1 change: 0 additions & 1 deletion dist/fuse.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,6 @@ class Fuse {
const result = evaluate(child, item, idx);
if (result.length) {
res.push(...result);
break
}
}
return res
Expand Down
2 changes: 1 addition & 1 deletion dist/fuse.esm.min.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions dist/fuse.js
Original file line number Diff line number Diff line change
Expand Up @@ -2089,8 +2089,6 @@

if (_result.length) {
_res.push.apply(_res, _toConsumableArray(_result));

break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion dist/fuse.min.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ export default class Fuse {
const result = evaluate(child, item, idx)
if (result.length) {
res.push(...result)
break
}
}
return res
Expand Down Expand Up @@ -286,4 +285,4 @@ export default class Fuse {

return matches
}
}
}
22 changes: 22 additions & 0 deletions test/logical-search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,25 @@ describe('Logical search with dotted keys', () => {
expect(result.length).toBe(1)
})
})

describe('Searching using logical OR with same query across fields', () => {
const options = { keys: ['title', 'author.lastName'] }
const fuse = new Fuse(Books, options)
let result
beforeEach(() => {
const query = {
$or: [
{ title: 'wood' },
{ 'author.lastName': 'wood' }
]
}

result = fuse.search(query)
})

describe('When searching for the term "wood"', () => {
test('we get the top three results scored based matches from all their fields', () => {
expect(idx(result.slice(0,3))).toMatchObject([4,3,5])
})
})
})