Skip to content

Commit 4f32573

Browse files
committed
Fix weight
1 parent f6c1319 commit 4f32573

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

app/lib/search/token_index.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,14 @@ class TokenIndex {
216216
/// Search the index for [words], with a (term-match / document coverage percent)
217217
/// scoring.
218218
Score searchWords(List<String> words, {double weight = 1.0}) {
219+
if (words.isEmpty) return Score.empty;
219220
IndexedScore? score;
221+
weight = math.pow(weight, 1 / words.length).toDouble();
220222
for (final w in words) {
221223
final s = IndexedScore(_ids);
222224
searchAndAccumulate(w, score: s, weight: weight);
223225
if (score == null) {
224226
score = s;
225-
// NOTE: in the subsequent round(s), weight will be re-applied on the next word(s) too.
226227
} else {
227228
score.multiplyAllFrom(s);
228229
}

app/test/search/api_doc_page_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void main() {
9999
'packageHits': [
100100
{
101101
'package': 'foo',
102-
'score': closeTo(0.18, 0.01), // find WebPageGenerator
102+
'score': closeTo(0.26, 0.01), // find WebPageGenerator
103103
'apiPages': [
104104
{'path': 'generator.html'},
105105
],
@@ -119,7 +119,7 @@ void main() {
119119
'packageHits': [
120120
{
121121
'package': 'foo',
122-
'score': closeTo(0.11, 0.01), // find WebPageGenerator
122+
'score': closeTo(0.16, 0.01), // find WebPageGenerator
123123
'apiPages': [
124124
{'path': 'generator.html'},
125125
],

0 commit comments

Comments
 (0)