Skip to content

Commit c37b63f

Browse files
authored
improve search match accuracy (#1986)
1 parent 81e8c36 commit c37b63f

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

util/search.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,30 @@ function calculateMatchScore(
1414
querySearch: string
1515
) {
1616
const exactNameMatchPoints =
17-
(!isEmptyOrNull(github.name) && github.name === querySearch) ||
18-
(!isEmptyOrNull(npmPkg) && npmPkg === querySearch)
17+
(!isEmptyOrNull(github.name) && github.name.toLowerCase() === querySearch) ||
18+
(!isEmptyOrNull(githubUrl) && githubUrl.toLowerCase() === querySearch) ||
19+
(!isEmptyOrNull(npmPkg) && npmPkg.toLowerCase() === querySearch)
1920
? 300
2021
: 0;
2122

2223
const npmPkgNameMatchPoints =
2324
!isEmptyOrNull(npmPkg) &&
2425
(npmPkg.includes(querySearch) ||
25-
npmPkg.replaceAll(NPM_NAME_CLEANUP_REGEX, ' ').includes(querySearch))
26+
npmPkg.replaceAll(NPM_NAME_CLEANUP_REGEX, ' ').toLowerCase().includes(querySearch))
2627
? 200
2728
: 0;
2829

2930
const gitHubURLOrOwnerMatchPoints =
3031
githubUrl.startsWith(querySearch) ||
31-
githubUrl.replace(GITHUB_URL_CLEANUP_REGEX, '$1').includes(querySearch)
32+
githubUrl.replace(GITHUB_URL_CLEANUP_REGEX, '$1').toLowerCase().includes(querySearch)
3233
? 150
3334
: 0;
3435

3536
const cleanedUpName = npmPkg
3637
.replace('react-native', '')
3738
.replace('react', '')
3839
.replaceAll(/[-/]/g, ' ')
40+
.toLowerCase()
3941
.trim();
4042

4143
const cleanedUpNameMatchPoints =
@@ -46,7 +48,7 @@ function calculateMatchScore(
4648
: 0;
4749

4850
const repoNameMatchPoints =
49-
!isEmptyOrNull(github.name) && github.name.includes(querySearch) ? 50 : 0;
51+
!isEmptyOrNull(github.name) && github.name.toLowerCase().includes(querySearch) ? 50 : 0;
5052

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

0 commit comments

Comments
 (0)