Skip to content

Commit da152f2

Browse files
committed
fix: try different approach with algolia by owner search
1 parent 0d952fa commit da152f2

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

app/composables/npm/useAlgoliaSearch.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ interface AlgoliaHit {
4343
modified: number
4444
homepage: string | null
4545
repository: AlgoliaRepo | null
46+
owner: AlgoliaOwner[] | null
4647
owners: AlgoliaOwner[] | null
4748
downloadsLast30Days: number
4849
downloadsRatio: number
@@ -60,6 +61,7 @@ const ATTRIBUTES_TO_RETRIEVE = [
6061
'modified',
6162
'homepage',
6263
'repository',
64+
'owner',
6365
'owners',
6466
'downloadsLast30Days',
6567
'downloadsRatio',
@@ -191,10 +193,11 @@ export function useAlgoliaSearch() {
191193
requests: [
192194
{
193195
indexName,
194-
query: '',
196+
query: ownerName,
195197
offset,
196198
length,
197-
filters: `owner.name:${ownerName}`,
199+
typoTolerance: false,
200+
restrictSearchableAttributes: ['owner.name', 'owners.name'],
198201
analyticsTags: ['npmx.dev'],
199202
attributesToRetrieve: ATTRIBUTES_TO_RETRIEVE,
200203
attributesToHighlight: [],
@@ -217,7 +220,12 @@ export function useAlgoliaSearch() {
217220

218221
return {
219222
isStale: false,
220-
objects: allHits.map(hitToSearchResult),
223+
// remove results where ownerName is not in owners and map for internal usage
224+
objects: allHits
225+
.filter(
226+
hit => hit?.owner?.name === ownerName || hit?.owners?.some(o => o.name === ownerName),
227+
)
228+
.map(hitToSearchResult),
221229
total: serverTotal,
222230
time: new Date().toISOString(),
223231
}

0 commit comments

Comments
 (0)