Skip to content

Commit d147d02

Browse files
authored
improvements to search scoring and relevance sort order (#2236)
1 parent e7e7238 commit d147d02

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

util/search.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,21 @@ const SUPPORT_PARAMS = [
1515
];
1616

1717
function calculateMatchScore(
18-
{ github, npmPkg, topicSearchString, unmaintained, githubUrl, vegaos }: LibraryType,
18+
{ github, npmPkg, topicSearchString, unmaintained, githubUrl, vegaos, score, npm }: LibraryType,
1919
querySearch: string
2020
) {
2121
const exactNameMatchPoints =
2222
(!isEmptyOrNull(github.name) && github.name.toLowerCase() === querySearch) ||
2323
(!isEmptyOrNull(githubUrl) && githubUrl.toLowerCase() === querySearch) ||
2424
(!isEmptyOrNull(npmPkg) && npmPkg.toLowerCase() === querySearch)
25-
? 300
25+
? 150
2626
: 0;
2727

2828
const npmPkgNameMatchPoints =
2929
!isEmptyOrNull(npmPkg) &&
3030
(npmPkg.includes(querySearch) ||
3131
npmPkg.replaceAll(NPM_NAME_CLEANUP_REGEX, ' ').toLowerCase().includes(querySearch))
32-
? 200
33-
: 0;
34-
35-
const gitHubURLOrOwnerMatchPoints =
36-
githubUrl.startsWith(querySearch) ||
37-
githubUrl.replace(GITHUB_URL_CLEANUP_REGEX, '$1').toLowerCase().includes(querySearch)
38-
? 150
32+
? 125
3933
: 0;
4034

4135
const cleanedUpName = npmPkg
@@ -52,11 +46,17 @@ function calculateMatchScore(
5246
? 100
5347
: 0;
5448

49+
const gitHubURLOrOwnerMatchPoints =
50+
githubUrl.startsWith(querySearch) ||
51+
githubUrl.replace(GITHUB_URL_CLEANUP_REGEX, '$1').toLowerCase().includes(querySearch)
52+
? 50
53+
: 0;
54+
5555
const repoNameMatchPoints =
5656
!isEmptyOrNull(github.name) && github.name.toLowerCase().includes(querySearch) ? 50 : 0;
5757

5858
const vegaOSPackageMatchPoints =
59-
typeof vegaos === 'string' && vegaos.includes(querySearch) ? 50 : 0;
59+
typeof vegaos === 'string' && vegaos.includes(querySearch) ? 25 : 0;
6060

6161
const descriptionMatchPoints =
6262
!isEmptyOrNull(github.description) && github.description?.toLowerCase().includes(querySearch)
@@ -77,8 +77,10 @@ function calculateMatchScore(
7777

7878
if (matchScore && unmaintained) {
7979
return matchScore / 1000;
80+
} else if (npm?.downloads && npm.downloads < 10_000) {
81+
return matchScore / 10;
8082
} else {
81-
return matchScore;
83+
return matchScore > 0 ? matchScore + score / 2 : matchScore;
8284
}
8385
}
8486

util/sorting.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ export function popularity(libraries: LibraryType[]) {
4747
export function relevance(libraries: LibraryType[]) {
4848
return libraries.sort((a, b) => {
4949
if (a.matchScore && b.matchScore) {
50-
if (Math.abs(a.matchScore - b.matchScore) >= 50) {
50+
if (a.matchScore < 10 || b.matchScore < 10 || Math.abs(a.matchScore - b.matchScore) >= 40) {
5151
return b.matchScore - a.matchScore;
5252
}
53-
5453
return b.score - a.score;
5554
}
5655
return 0;

0 commit comments

Comments
 (0)