Skip to content

Commit 362413e

Browse files
authored
Increase description/topic weights by removing the document length compensation. (#8294)
1 parent d7efc04 commit 362413e

File tree

7 files changed

+20
-14
lines changed

7 files changed

+20
-14
lines changed

app/lib/search/mem_index.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class InMemoryPackageIndex {
7979
_descrIndex = TokenIndex(
8080
packageKeys,
8181
_documents.map((d) => d.description).toList(),
82+
skipDocumentWeight: true,
8283
);
8384
_readmeIndex = TokenIndex(
8485
packageKeys,

app/lib/search/token_index.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ class TokenIndex<K> {
3434

3535
late final _length = _ids.length;
3636

37-
TokenIndex(List<K> ids, List<String?> values) : _ids = ids {
37+
TokenIndex(
38+
List<K> ids,
39+
List<String?> values, {
40+
bool skipDocumentWeight = false,
41+
}) : _ids = ids {
3842
assert(ids.length == values.length);
3943
final length = values.length;
4044
for (var i = 0; i < length; i++) {
@@ -48,7 +52,8 @@ class TokenIndex<K> {
4852
continue;
4953
}
5054
// Document weight is a highly scaled-down proxy of the length.
51-
final dw = 1 + math.log(1 + tokens.length) / 100;
55+
final dw =
56+
skipDocumentWeight ? 1.0 : 1 + math.log(1 + tokens.length) / 100;
5257
for (final e in tokens.entries) {
5358
final token = e.key;
5459
final weights = _inverseIds.putIfAbsent(token, () => {});

app/test/search/bluetooth_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void main() {
4040
'packageHits': [
4141
{
4242
'package': 'flutter_blue',
43-
'score': closeTo(0.98, 0.01),
43+
'score': 1.0,
4444
},
4545
],
4646
});

app/test/search/in_app_payments_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Add _In-App Payments_ to your Flutter app with this plugin.''')),
5252
'packageHits': [
5353
{
5454
'package': 'flutter_iap',
55-
'score': closeTo(0.70, 0.01),
55+
'score': closeTo(0.73, 0.01),
5656
},
5757
],
5858
});

app/test/search/json_tool_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ void main() {
6868
'totalCount': 3,
6969
'sdkLibraryHits': [],
7070
'packageHits': [
71+
{'package': 'json2entity', 'score': 1.0},
7172
{'package': 'jsontool', 'score': 1.0},
72-
{'package': 'json2entity', 'score': closeTo(0.97, 0.01)},
7373
{'package': 'json_to_model', 'score': closeTo(0.73, 0.01)},
7474
],
7575
});

app/test/search/mem_index_test.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
109109
'packageHits': [
110110
{
111111
'package': 'http',
112-
'score': closeTo(0.93, 0.01),
112+
'score': closeTo(0.96, 0.01),
113113
},
114114
],
115115
});
@@ -140,7 +140,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
140140
'sdkLibraryHits': [],
141141
'packageHits': [
142142
{'package': 'http', 'score': closeTo(0.69, 0.01)},
143-
{'package': 'async', 'score': closeTo(0.63, 0.01)},
143+
{'package': 'async', 'score': closeTo(0.65, 0.01)},
144144
],
145145
});
146146
});
@@ -381,7 +381,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
381381
'totalCount': 1,
382382
'sdkLibraryHits': [],
383383
'packageHits': [
384-
{'package': 'http', 'score': closeTo(0.93, 0.01)},
384+
{'package': 'http', 'score': closeTo(0.96, 0.01)},
385385
],
386386
});
387387
});
@@ -494,7 +494,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
494494
'totalCount': 1,
495495
'sdkLibraryHits': [],
496496
'packageHits': [
497-
{'package': 'http', 'score': closeTo(0.98, 0.01)},
497+
{'package': 'http', 'score': 1.0},
498498
],
499499
});
500500

@@ -505,8 +505,8 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
505505
'totalCount': 3,
506506
'sdkLibraryHits': [],
507507
'packageHits': [
508-
{'package': 'chrome_net', 'score': closeTo(0.98, 0.01)},
509-
{'package': 'async', 'score': closeTo(0.98, 0.01)},
508+
{'package': 'async', 'score': 1.0},
509+
{'package': 'chrome_net', 'score': 1.0},
510510
{'package': 'http', 'score': closeTo(0.72, 0.01)},
511511
],
512512
});
@@ -520,7 +520,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
520520
'totalCount': 1,
521521
'sdkLibraryHits': [],
522522
'packageHits': [
523-
{'package': 'http', 'score': closeTo(0.70, 0.01)},
523+
{'package': 'http', 'score': closeTo(0.72, 0.01)},
524524
],
525525
});
526526
});
@@ -690,7 +690,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
690690
'sdkLibraryHits': [],
691691
'packageHits': [
692692
{'package': 'flutter_modular', 'score': 1.0},
693-
{'package': 'serveme', 'score': closeTo(0.97, 0.01)},
693+
{'package': 'serveme', 'score': 1.0},
694694
]
695695
},
696696
);

app/test/search/rest_api_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Recent versions (0.3.x and 0.4.x) of this plugin require [extensible codec funct
5757
'packageHits': [
5858
{
5959
'package': 'currency_cloud',
60-
'score': closeTo(0.95, 0.01),
60+
'score': 1.0,
6161
},
6262
{
6363
'package': 'cloud_firestore', // finds `rest` in name

0 commit comments

Comments
 (0)