Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(relevance): use jsDelivr hits for ranking #269

Merged
merged 1 commit into from
Sep 14, 2018
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ For every single NPM package, we create a record in the Algolia index. The resul
"objectID": "babel-core",
"_searchInternal": {
"popularName": "babel-core",
"downloadsMagnitude": 8
"downloadsMagnitude": 8,
"jsDelivrPopularity": 5
}
}
```
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/__snapshots__/config.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Object {
],
"customRanking": Array [
"desc(_searchInternal.downloadsMagnitude)",
"desc(_searchInternal.jsDelivrPopularity)",
"desc(dependents)",
"desc(downloadsLast30Days)",
],
Expand Down
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const defaultConfig = {
],
customRanking: [
'desc(_searchInternal.downloadsMagnitude)',
'desc(_searchInternal.jsDelivrPopularity)',
'desc(dependents)',
'desc(downloadsLast30Days)',
],
Expand Down
13 changes: 12 additions & 1 deletion src/jsDelivr.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,16 @@ export async function loadHits() {
}

export function getHits(pkgs) {
return pkgs.map(({ name }) => ({ jsDelivrHits: hits.get(name) || 0 }));
return pkgs.map(({ name }) => {
const jsDelivrHits = hits.get(name) || 0;

return {
jsDelivrHits,
_searchInternal: {
// anything below 1000 hits/month is likely to mean that
// someone just made a few random requests so we count that as 0
jsDelivrPopularity: Math.max(jsDelivrHits.toString().length - 3, 0),
},
};
});
}