Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions app/lib/search/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:math';

import 'package:clock/clock.dart';
import 'package:collection/collection.dart';
import 'package:json_annotation/json_annotation.dart';
Expand Down Expand Up @@ -68,7 +70,7 @@ extension UpdateLikesExt on Iterable<PackageDocument> {
if (i > 0 && list[i - 1].downloadCount == list[i].downloadCount) {
list[i].downloadScore = list[i - 1].downloadScore;
} else {
list[i].downloadScore = (i + 1) / list.length;
list[i].downloadScore = pow((i + 1) / list.length, 2).toDouble();
}
}
}
Expand All @@ -77,13 +79,12 @@ extension UpdateLikesExt on Iterable<PackageDocument> {
/// The score is normalized into the range of [0.0 - 1.0] using the
/// ordered list of packages by like counts (same like count gets the same score).
void updateLikeScores() {
final sortedByLikes = sorted((a, b) => a.likeCount.compareTo(b.likeCount));
for (var i = 0; i < sortedByLikes.length; i++) {
if (i > 0 &&
sortedByLikes[i - 1].likeCount == sortedByLikes[i].likeCount) {
sortedByLikes[i].likeScore = sortedByLikes[i - 1].likeScore;
final list = sorted((a, b) => a.likeCount.compareTo(b.likeCount));
for (var i = 0; i < list.length; i++) {
if (i > 0 && list[i - 1].likeCount == list[i].likeCount) {
list[i].likeScore = list[i - 1].likeScore;
} else {
sortedByLikes[i].likeScore = (i + 1) / sortedByLikes.length;
list[i].likeScore = pow((i + 1) / list.length, 2).toDouble();
}
}
}
Expand Down
28 changes: 14 additions & 14 deletions app/test/search/mem_index_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
'totalCount': 1,
'sdkLibraryHits': [],
'packageHits': [
{'package': 'async', 'score': closeTo(0.71, 0.01)},
{'package': 'async', 'score': closeTo(0.68, 0.01)},
],
});
});
Expand Down Expand Up @@ -134,7 +134,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
'totalCount': 1,
'sdkLibraryHits': [],
'packageHits': [
{'package': 'chrome_net', 'score': closeTo(0.33, 0.01)},
{'package': 'chrome_net', 'score': closeTo(0.30, 0.01)},
],
});
});
Expand All @@ -148,8 +148,8 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
'totalCount': 2,
'sdkLibraryHits': [],
'packageHits': [
{'package': 'async', 'score': closeTo(0.71, 0.01)},
{'package': 'http', 'score': closeTo(0.69, 0.01)},
{'package': 'async', 'score': closeTo(0.67, 0.01)},
],
});
});
Expand All @@ -163,7 +163,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
'totalCount': 1,
'sdkLibraryHits': [],
'packageHits': [
{'package': 'async', 'score': closeTo(0.37, 0.01)},
{'package': 'async', 'score': closeTo(0.35, 0.01)},
],
});
});
Expand Down Expand Up @@ -348,7 +348,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
'sdkLibraryHits': [],
'packageHits': [
{'package': 'http', 'score': closeTo(0.92, 0.01)},
{'package': 'async', 'score': closeTo(0.52, 0.01)},
{'package': 'async', 'score': closeTo(0.46, 0.01)},
],
});

Expand All @@ -368,7 +368,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
'totalCount': 1,
'sdkLibraryHits': [],
'packageHits': [
{'package': 'chrome_net', 'score': closeTo(0.08, 0.01)},
{'package': 'chrome_net', 'score': closeTo(0.03, 0.01)},
],
});
});
Expand All @@ -383,7 +383,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
'sdkLibraryHits': [],
'packageHits': [
{'package': 'http', 'score': closeTo(0.92, 0.01)},
{'package': 'chrome_net', 'score': closeTo(0.08, 0.01)},
{'package': 'chrome_net', 'score': closeTo(0.03, 0.01)},
],
});

Expand Down Expand Up @@ -443,7 +443,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
'totalCount': 1,
'sdkLibraryHits': [],
'packageHits': [
{'package': 'async', 'score': closeTo(0.52, 0.01)},
{'package': 'async', 'score': closeTo(0.46, 0.01)},
],
});

Expand Down Expand Up @@ -677,7 +677,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
'totalCount': 2,
'sdkLibraryHits': [],
'packageHits': [
{'package': 'def', 'score': closeTo(0.85, 0.01)},
{'package': 'def', 'score': closeTo(0.78, 0.01)},
{'package': 'abc', 'score': closeTo(0.70, 0.01)},
],
},
Expand All @@ -693,7 +693,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
'packageHits': [
// `abc` is at the first position, score is kept
{'package': 'abc', 'score': closeTo(0.70, 0.01)},
{'package': 'def', 'score': closeTo(0.85, 0.01)},
{'package': 'def', 'score': closeTo(0.78, 0.01)},
],
},
);
Expand All @@ -705,7 +705,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
'totalCount': 2,
'sdkLibraryHits': [],
'packageHits': [
{'package': 'def', 'score': closeTo(0.85, 0.01)},
{'package': 'def', 'score': closeTo(0.78, 0.01)},
{'package': 'abc', 'score': closeTo(0.70, 0.01)},
],
},
Expand All @@ -721,7 +721,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
'sdkLibraryHits': [],
'packageHits': [
// `abc` is at the original position
{'package': 'def', 'score': closeTo(0.85, 0.01)},
{'package': 'def', 'score': closeTo(0.78, 0.01)},
{'package': 'abc', 'score': closeTo(0.70, 0.01)},
],
},
Expand All @@ -737,7 +737,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
'sdkLibraryHits': [],
'packageHits': [
// `abc` is absent
{'package': 'def', 'score': closeTo(0.85, 0.01)},
{'package': 'def', 'score': closeTo(0.78, 0.01)},
],
},
);
Expand Down Expand Up @@ -775,7 +775,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
'nameMatches': ['abc_def'],
'sdkLibraryHits': [],
'packageHits': [
{'package': 'abc_def', 'score': closeTo(0.55, 0.01)},
{'package': 'abc_def', 'score': closeTo(0.48, 0.01)},
{'package': 'abc_def_xyz', 'score': closeTo(1.0, 0.01)},
],
});
Expand Down
2 changes: 1 addition & 1 deletion app/test/service/entrypoint/search_index_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void main() {
'totalCount': 1,
'sdkLibraryHits': [],
'packageHits': [
{'package': 'json_annotation', 'score': greaterThan(0.5)},
{'package': 'json_annotation', 'score': greaterThan(0.47)},
],
});

Expand Down