Skip to content
Draft
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
14 changes: 11 additions & 3 deletions app/composables/npm/useAlgoliaSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface AlgoliaHit {
modified: number
homepage: string | null
repository: AlgoliaRepo | null
owner: AlgoliaOwner | null
owners: AlgoliaOwner[] | null
downloadsLast30Days: number
downloadsRatio: number
Expand All @@ -60,6 +61,7 @@ const ATTRIBUTES_TO_RETRIEVE = [
'modified',
'homepage',
'repository',
'owner',
'owners',
'downloadsLast30Days',
'downloadsRatio',
Expand Down Expand Up @@ -191,10 +193,11 @@ export function useAlgoliaSearch() {
requests: [
{
indexName,
query: '',
query: ownerName,
offset,
length,
filters: `owner.name:${ownerName}`,
typoTolerance: false,
restrictSearchableAttributes: ['owner.name', 'owners.name'],
analyticsTags: ['npmx.dev'],
attributesToRetrieve: ATTRIBUTES_TO_RETRIEVE,
attributesToHighlight: [],
Expand All @@ -217,7 +220,12 @@ export function useAlgoliaSearch() {

return {
isStale: false,
objects: allHits.map(hitToSearchResult),
// remove results where ownerName is not in owners and map for internal usage
objects: allHits
.filter(
hit => hit?.owner?.name === ownerName || hit?.owners?.some(o => o.name === ownerName),
)
.map(hitToSearchResult),
total: serverTotal,
time: new Date().toISOString(),
}
Expand Down
Loading