Skip to content
Merged
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
24 changes: 13 additions & 11 deletions util/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,21 @@ const SUPPORT_PARAMS = [
];

function calculateMatchScore(
{ github, npmPkg, topicSearchString, unmaintained, githubUrl, vegaos }: LibraryType,
{ github, npmPkg, topicSearchString, unmaintained, githubUrl, vegaos, score, npm }: LibraryType,
querySearch: string
) {
const exactNameMatchPoints =
(!isEmptyOrNull(github.name) && github.name.toLowerCase() === querySearch) ||
(!isEmptyOrNull(githubUrl) && githubUrl.toLowerCase() === querySearch) ||
(!isEmptyOrNull(npmPkg) && npmPkg.toLowerCase() === querySearch)
? 300
? 150
: 0;

const npmPkgNameMatchPoints =
!isEmptyOrNull(npmPkg) &&
(npmPkg.includes(querySearch) ||
npmPkg.replaceAll(NPM_NAME_CLEANUP_REGEX, ' ').toLowerCase().includes(querySearch))
? 200
: 0;

const gitHubURLOrOwnerMatchPoints =
githubUrl.startsWith(querySearch) ||
githubUrl.replace(GITHUB_URL_CLEANUP_REGEX, '$1').toLowerCase().includes(querySearch)
? 150
? 125
: 0;

const cleanedUpName = npmPkg
Expand All @@ -52,11 +46,17 @@ function calculateMatchScore(
? 100
: 0;

const gitHubURLOrOwnerMatchPoints =
githubUrl.startsWith(querySearch) ||
githubUrl.replace(GITHUB_URL_CLEANUP_REGEX, '$1').toLowerCase().includes(querySearch)
? 50
: 0;

const repoNameMatchPoints =
!isEmptyOrNull(github.name) && github.name.toLowerCase().includes(querySearch) ? 50 : 0;

const vegaOSPackageMatchPoints =
typeof vegaos === 'string' && vegaos.includes(querySearch) ? 50 : 0;
typeof vegaos === 'string' && vegaos.includes(querySearch) ? 25 : 0;

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

if (matchScore && unmaintained) {
return matchScore / 1000;
} else if (npm?.downloads && npm.downloads < 10_000) {
return matchScore / 10;
} else {
return matchScore;
return matchScore > 0 ? matchScore + score / 2 : matchScore;
}
}

Expand Down
3 changes: 1 addition & 2 deletions util/sorting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ export function popularity(libraries: LibraryType[]) {
export function relevance(libraries: LibraryType[]) {
return libraries.sort((a, b) => {
if (a.matchScore && b.matchScore) {
if (Math.abs(a.matchScore - b.matchScore) >= 50) {
if (a.matchScore < 10 || b.matchScore < 10 || Math.abs(a.matchScore - b.matchScore) >= 40) {
return b.matchScore - a.matchScore;
}

return b.score - a.score;
}
return 0;
Expand Down