Skip to content

Commit

Permalink
fix(extended): correctly score include-match results
Browse files Browse the repository at this point in the history
change score to 0/1 when matched/not matched, respectively

fixes #522
  • Loading branch information
skearney6 authored and krisk committed Dec 29, 2020
1 parent 33be0ac commit 443c863
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion dist/fuse.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,7 @@ var IncludeMatch = /*#__PURE__*/function (_BaseMatch) {
var isMatch = !!indices.length;
return {
isMatch: isMatch,
score: isMatch ? 1 : 0,
score: isMatch ? 0 : 1,
indices: indices
};
}
Expand Down
2 changes: 1 addition & 1 deletion dist/fuse.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ class IncludeMatch extends BaseMatch {

return {
isMatch,
score: isMatch ? 1 : 0,
score: isMatch ? 0 : 1,
indices
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/fuse.esm.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/fuse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@
var isMatch = !!indices.length;
return {
isMatch: isMatch,
score: isMatch ? 1 : 0,
score: isMatch ? 0 : 1,
indices: indices
};
}
Expand Down
2 changes: 1 addition & 1 deletion dist/fuse.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/search/extended/IncludeMatch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Token: 'file
// Match type: exact-match
// Match type: include-match
// Description: Items that include `file`

import BaseMatch from './BaseMatch'
Expand Down Expand Up @@ -34,7 +34,7 @@ export default class IncludeMatch extends BaseMatch {

return {
isMatch,
score: isMatch ? 1 : 0,
score: isMatch ? 0 : 1,
indices
}
}
Expand Down
66 changes: 33 additions & 33 deletions test/__snapshots__/extended-search.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Array [
},
],
"refIndex": 0,
"score": 1,
"score": 8.569061098350962e-12,
},
Object {
"item": Object {
Expand All @@ -159,7 +159,7 @@ Array [
},
],
"refIndex": 2,
"score": 1,
"score": 1.4901161193847656e-8,
},
]
`;
Expand Down Expand Up @@ -468,45 +468,45 @@ exports[`Searching using extended search Search: literal match with fuzzy match
Array [
Object {
"item": Object {
"text": "hello word",
"text": "indeed fine hello foo",
},
"matches": Array [
Object {
"indices": Array [
Array [
0,
4,
10,
],
Array [
18,
20,
],
],
"key": "text",
"value": "hello word",
"value": "indeed fine hello foo",
},
],
"refIndex": 0,
"score": 0.3205001277290518,
"refIndex": 2,
"score": 1.4901161193847656e-8,
},
Object {
"item": Object {
"text": "indeed fine hello foo",
"text": "hello word",
},
"matches": Array [
Object {
"indices": Array [
Array [
0,
10,
],
Array [
18,
20,
4,
],
],
"key": "text",
"value": "indeed fine hello foo",
"value": "hello word",
},
],
"refIndex": 2,
"score": 0.7071067811865476,
"refIndex": 0,
"score": 0.3205001277290518,
},
]
`;
Expand All @@ -515,45 +515,45 @@ exports[`Searching using extended search Search: literal match with regular matc
Array [
Object {
"item": Object {
"text": "indeed fine hello foo",
"text": "how are you",
},
"matches": Array [
Object {
"indices": Array [
Array [
0,
10,
],
Array [
18,
20,
4,
6,
],
],
"key": "text",
"value": "indeed fine hello foo",
"value": "how are you",
},
],
"refIndex": 2,
"score": 0.7071067811865476,
"refIndex": 1,
"score": 9.287439764962262e-10,
},
Object {
"item": Object {
"text": "how are you",
"text": "indeed fine hello foo",
},
"matches": Array [
Object {
"indices": Array [
Array [
4,
6,
0,
10,
],
Array [
18,
20,
],
],
"key": "text",
"value": "how are you",
"value": "indeed fine hello foo",
},
],
"refIndex": 1,
"score": 1,
"refIndex": 2,
"score": 1.4901161193847656e-8,
},
]
`;
Expand Down Expand Up @@ -601,7 +601,7 @@ Array [
},
],
"refIndex": 2,
"score": 1,
"score": 1.4901161193847656e-8,
},
]
`;
Expand Down

0 comments on commit 443c863

Please sign in to comment.