diff --git a/app/composables/npm/useAlgoliaSearch.ts b/app/composables/npm/useAlgoliaSearch.ts index eb10a2e7ae..9af47d07de 100644 --- a/app/composables/npm/useAlgoliaSearch.ts +++ b/app/composables/npm/useAlgoliaSearch.ts @@ -43,6 +43,7 @@ interface AlgoliaHit { modified: number homepage: string | null repository: AlgoliaRepo | null + owner: AlgoliaOwner | null owners: AlgoliaOwner[] | null downloadsLast30Days: number downloadsRatio: number @@ -60,6 +61,7 @@ const ATTRIBUTES_TO_RETRIEVE = [ 'modified', 'homepage', 'repository', + 'owner', 'owners', 'downloadsLast30Days', 'downloadsRatio', @@ -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: [], @@ -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(), }