Skip to content

Commit 9039f76

Browse files
MartinKolarikHaroenv
authored andcommitted
feat(relevance): use jsDelivr hits for ranking (#269)
1 parent adff89d commit 9039f76

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ For every single NPM package, we create a record in the Algolia index. The resul
124124
"objectID": "babel-core",
125125
"_searchInternal": {
126126
"popularName": "babel-core",
127-
"downloadsMagnitude": 8
127+
"downloadsMagnitude": 8,
128+
"jsDelivrPopularity": 5
128129
}
129130
}
130131
```

src/__tests__/__snapshots__/config.test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Object {
3434
],
3535
"customRanking": Array [
3636
"desc(_searchInternal.downloadsMagnitude)",
37+
"desc(_searchInternal.jsDelivrPopularity)",
3738
"desc(dependents)",
3839
"desc(downloadsLast30Days)",
3940
],

src/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const defaultConfig = {
3333
],
3434
customRanking: [
3535
'desc(_searchInternal.downloadsMagnitude)',
36+
'desc(_searchInternal.jsDelivrPopularity)',
3637
'desc(dependents)',
3738
'desc(downloadsLast30Days)',
3839
],

src/jsDelivr.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,16 @@ export async function loadHits() {
1919
}
2020

2121
export function getHits(pkgs) {
22-
return pkgs.map(({ name }) => ({ jsDelivrHits: hits.get(name) || 0 }));
22+
return pkgs.map(({ name }) => {
23+
const jsDelivrHits = hits.get(name) || 0;
24+
25+
return {
26+
jsDelivrHits,
27+
_searchInternal: {
28+
// anything below 1000 hits/month is likely to mean that
29+
// someone just made a few random requests so we count that as 0
30+
jsDelivrPopularity: Math.max(jsDelivrHits.toString().length - 3, 0),
31+
},
32+
};
33+
});
2334
}

0 commit comments

Comments
 (0)