Skip to content

Commit

Permalink
Increase description/topic weights by removing the document length co…
Browse files Browse the repository at this point in the history
…mpensation. (dart-lang#8294)
  • Loading branch information
isoos authored Nov 15, 2024
1 parent d7efc04 commit 362413e
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 14 deletions.
1 change: 1 addition & 0 deletions app/lib/search/mem_index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class InMemoryPackageIndex {
_descrIndex = TokenIndex(
packageKeys,
_documents.map((d) => d.description).toList(),
skipDocumentWeight: true,
);
_readmeIndex = TokenIndex(
packageKeys,
Expand Down
9 changes: 7 additions & 2 deletions app/lib/search/token_index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ class TokenIndex<K> {

late final _length = _ids.length;

TokenIndex(List<K> ids, List<String?> values) : _ids = ids {
TokenIndex(
List<K> ids,
List<String?> values, {
bool skipDocumentWeight = false,
}) : _ids = ids {
assert(ids.length == values.length);
final length = values.length;
for (var i = 0; i < length; i++) {
Expand All @@ -48,7 +52,8 @@ class TokenIndex<K> {
continue;
}
// Document weight is a highly scaled-down proxy of the length.
final dw = 1 + math.log(1 + tokens.length) / 100;
final dw =
skipDocumentWeight ? 1.0 : 1 + math.log(1 + tokens.length) / 100;
for (final e in tokens.entries) {
final token = e.key;
final weights = _inverseIds.putIfAbsent(token, () => {});
Expand Down
2 changes: 1 addition & 1 deletion app/test/search/bluetooth_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void main() {
'packageHits': [
{
'package': 'flutter_blue',
'score': closeTo(0.98, 0.01),
'score': 1.0,
},
],
});
Expand Down
2 changes: 1 addition & 1 deletion app/test/search/in_app_payments_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Add _In-App Payments_ to your Flutter app with this plugin.''')),
'packageHits': [
{
'package': 'flutter_iap',
'score': closeTo(0.70, 0.01),
'score': closeTo(0.73, 0.01),
},
],
});
Expand Down
2 changes: 1 addition & 1 deletion app/test/search/json_tool_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ void main() {
'totalCount': 3,
'sdkLibraryHits': [],
'packageHits': [
{'package': 'json2entity', 'score': 1.0},
{'package': 'jsontool', 'score': 1.0},
{'package': 'json2entity', 'score': closeTo(0.97, 0.01)},
{'package': 'json_to_model', 'score': closeTo(0.73, 0.01)},
],
});
Expand Down
16 changes: 8 additions & 8 deletions app/test/search/mem_index_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
'packageHits': [
{
'package': 'http',
'score': closeTo(0.93, 0.01),
'score': closeTo(0.96, 0.01),
},
],
});
Expand Down Expand Up @@ -140,7 +140,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
'sdkLibraryHits': [],
'packageHits': [
{'package': 'http', 'score': closeTo(0.69, 0.01)},
{'package': 'async', 'score': closeTo(0.63, 0.01)},
{'package': 'async', 'score': closeTo(0.65, 0.01)},
],
});
});
Expand Down Expand Up @@ -381,7 +381,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
'totalCount': 1,
'sdkLibraryHits': [],
'packageHits': [
{'package': 'http', 'score': closeTo(0.93, 0.01)},
{'package': 'http', 'score': closeTo(0.96, 0.01)},
],
});
});
Expand Down Expand Up @@ -494,7 +494,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
'totalCount': 1,
'sdkLibraryHits': [],
'packageHits': [
{'package': 'http', 'score': closeTo(0.98, 0.01)},
{'package': 'http', 'score': 1.0},
],
});

Expand All @@ -505,8 +505,8 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
'totalCount': 3,
'sdkLibraryHits': [],
'packageHits': [
{'package': 'chrome_net', 'score': closeTo(0.98, 0.01)},
{'package': 'async', 'score': closeTo(0.98, 0.01)},
{'package': 'async', 'score': 1.0},
{'package': 'chrome_net', 'score': 1.0},
{'package': 'http', 'score': closeTo(0.72, 0.01)},
],
});
Expand All @@ -520,7 +520,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
'totalCount': 1,
'sdkLibraryHits': [],
'packageHits': [
{'package': 'http', 'score': closeTo(0.70, 0.01)},
{'package': 'http', 'score': closeTo(0.72, 0.01)},
],
});
});
Expand Down Expand Up @@ -690,7 +690,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
'sdkLibraryHits': [],
'packageHits': [
{'package': 'flutter_modular', 'score': 1.0},
{'package': 'serveme', 'score': closeTo(0.97, 0.01)},
{'package': 'serveme', 'score': 1.0},
]
},
);
Expand Down
2 changes: 1 addition & 1 deletion app/test/search/rest_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Recent versions (0.3.x and 0.4.x) of this plugin require [extensible codec funct
'packageHits': [
{
'package': 'currency_cloud',
'score': closeTo(0.95, 0.01),
'score': 1.0,
},
{
'package': 'cloud_firestore', // finds `rest` in name
Expand Down

0 comments on commit 362413e

Please sign in to comment.