Skip to content

Commit 443c863

Browse files
skearney6krisk
authored andcommitted
fix(extended): correctly score include-match results
change score to 0/1 when matched/not matched, respectively fixes #522
1 parent 33be0ac commit 443c863

7 files changed

Lines changed: 40 additions & 40 deletions

File tree

dist/fuse.common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,7 @@ var IncludeMatch = /*#__PURE__*/function (_BaseMatch) {
14991499
var isMatch = !!indices.length;
15001500
return {
15011501
isMatch: isMatch,
1502-
score: isMatch ? 1 : 0,
1502+
score: isMatch ? 0 : 1,
15031503
indices: indices
15041504
};
15051505
}

dist/fuse.esm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ class IncludeMatch extends BaseMatch {
11251125

11261126
return {
11271127
isMatch,
1128-
score: isMatch ? 1 : 0,
1128+
score: isMatch ? 0 : 1,
11291129
indices
11301130
}
11311131
}

dist/fuse.esm.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/fuse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,7 @@
15031503
var isMatch = !!indices.length;
15041504
return {
15051505
isMatch: isMatch,
1506-
score: isMatch ? 1 : 0,
1506+
score: isMatch ? 0 : 1,
15071507
indices: indices
15081508
};
15091509
}

dist/fuse.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/search/extended/IncludeMatch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Token: 'file
2-
// Match type: exact-match
2+
// Match type: include-match
33
// Description: Items that include `file`
44

55
import BaseMatch from './BaseMatch'
@@ -34,7 +34,7 @@ export default class IncludeMatch extends BaseMatch {
3434

3535
return {
3636
isMatch,
37-
score: isMatch ? 1 : 0,
37+
score: isMatch ? 0 : 1,
3838
indices
3939
}
4040
}

test/__snapshots__/extended-search.test.js.snap

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Array [
140140
},
141141
],
142142
"refIndex": 0,
143-
"score": 1,
143+
"score": 8.569061098350962e-12,
144144
},
145145
Object {
146146
"item": Object {
@@ -159,7 +159,7 @@ Array [
159159
},
160160
],
161161
"refIndex": 2,
162-
"score": 1,
162+
"score": 1.4901161193847656e-8,
163163
},
164164
]
165165
`;
@@ -468,45 +468,45 @@ exports[`Searching using extended search Search: literal match with fuzzy match
468468
Array [
469469
Object {
470470
"item": Object {
471-
"text": "hello word",
471+
"text": "indeed fine hello foo",
472472
},
473473
"matches": Array [
474474
Object {
475475
"indices": Array [
476476
Array [
477477
0,
478-
4,
478+
10,
479+
],
480+
Array [
481+
18,
482+
20,
479483
],
480484
],
481485
"key": "text",
482-
"value": "hello word",
486+
"value": "indeed fine hello foo",
483487
},
484488
],
485-
"refIndex": 0,
486-
"score": 0.3205001277290518,
489+
"refIndex": 2,
490+
"score": 1.4901161193847656e-8,
487491
},
488492
Object {
489493
"item": Object {
490-
"text": "indeed fine hello foo",
494+
"text": "hello word",
491495
},
492496
"matches": Array [
493497
Object {
494498
"indices": Array [
495499
Array [
496500
0,
497-
10,
498-
],
499-
Array [
500-
18,
501-
20,
501+
4,
502502
],
503503
],
504504
"key": "text",
505-
"value": "indeed fine hello foo",
505+
"value": "hello word",
506506
},
507507
],
508-
"refIndex": 2,
509-
"score": 0.7071067811865476,
508+
"refIndex": 0,
509+
"score": 0.3205001277290518,
510510
},
511511
]
512512
`;
@@ -515,45 +515,45 @@ exports[`Searching using extended search Search: literal match with regular matc
515515
Array [
516516
Object {
517517
"item": Object {
518-
"text": "indeed fine hello foo",
518+
"text": "how are you",
519519
},
520520
"matches": Array [
521521
Object {
522522
"indices": Array [
523523
Array [
524-
0,
525-
10,
526-
],
527-
Array [
528-
18,
529-
20,
524+
4,
525+
6,
530526
],
531527
],
532528
"key": "text",
533-
"value": "indeed fine hello foo",
529+
"value": "how are you",
534530
},
535531
],
536-
"refIndex": 2,
537-
"score": 0.7071067811865476,
532+
"refIndex": 1,
533+
"score": 9.287439764962262e-10,
538534
},
539535
Object {
540536
"item": Object {
541-
"text": "how are you",
537+
"text": "indeed fine hello foo",
542538
},
543539
"matches": Array [
544540
Object {
545541
"indices": Array [
546542
Array [
547-
4,
548-
6,
543+
0,
544+
10,
545+
],
546+
Array [
547+
18,
548+
20,
549549
],
550550
],
551551
"key": "text",
552-
"value": "how are you",
552+
"value": "indeed fine hello foo",
553553
},
554554
],
555-
"refIndex": 1,
556-
"score": 1,
555+
"refIndex": 2,
556+
"score": 1.4901161193847656e-8,
557557
},
558558
]
559559
`;
@@ -601,7 +601,7 @@ Array [
601601
},
602602
],
603603
"refIndex": 2,
604-
"score": 1,
604+
"score": 1.4901161193847656e-8,
605605
},
606606
]
607607
`;

0 commit comments

Comments
 (0)