diff --git a/apps/researcher/src/lib/api/objects/definitions.ts b/apps/researcher/src/lib/api/objects/definitions.ts index 3929c2812..b8cee65d5 100644 --- a/apps/researcher/src/lib/api/objects/definitions.ts +++ b/apps/researcher/src/lib/api/objects/definitions.ts @@ -19,5 +19,6 @@ export type SearchResult = { locations: SearchResultFilter[]; materials: SearchResultFilter[]; creators: SearchResultFilter[]; + publishers: SearchResultFilter[]; }; }; diff --git a/apps/researcher/src/lib/api/objects/searcher.integration.test.ts b/apps/researcher/src/lib/api/objects/searcher.integration.test.ts index b03817ff0..00bcc12a5 100644 --- a/apps/researcher/src/lib/api/objects/searcher.integration.test.ts +++ b/apps/researcher/src/lib/api/objects/searcher.integration.test.ts @@ -388,6 +388,33 @@ describe('search', () => { name: 'Vincent van Gogh', }, ], + publishers: [ + { + totalCount: 0, + id: 'Archive', + name: 'Archive', + }, + { + totalCount: 1, + id: 'Library', + name: 'Library', + }, + { + totalCount: 3, + id: 'Museum', + name: 'Museum', + }, + { + totalCount: 1, + id: 'Onderzoeksinstelling', + name: 'Onderzoeksinstelling', + }, + { + totalCount: 1, + id: 'Research Organisation', + name: 'Research Organisation', + }, + ], }, }); }); @@ -540,4 +567,45 @@ describe('search', () => { }, }); }); + + it('finds heritage objects if "publishers" filter matches', async () => { + const result = await heritageObjectSearcher.search({ + filters: { + publishers: ['Library'], + }, + }); + + expect(result).toMatchObject({ + totalCount: 1, + filters: { + publishers: [ + { + totalCount: 0, + id: 'Archive', + name: 'Archive', + }, + { + totalCount: 1, + id: 'Library', + name: 'Library', + }, + { + totalCount: 0, + id: 'Museum', + name: 'Museum', + }, + { + totalCount: 0, + id: 'Onderzoeksinstelling', + name: 'Onderzoeksinstelling', + }, + { + totalCount: 0, + id: 'Research Organisation', + name: 'Research Organisation', + }, + ], + }, + }); + }); }); diff --git a/apps/researcher/src/lib/api/objects/searcher.ts b/apps/researcher/src/lib/api/objects/searcher.ts index f3202d0ef..7b2f73336 100644 --- a/apps/researcher/src/lib/api/objects/searcher.ts +++ b/apps/researcher/src/lib/api/objects/searcher.ts @@ -62,6 +62,7 @@ const searchOptionsSchema = z.object({ locations: z.array(z.string()).optional().default([]), materials: z.array(z.string()).optional().default([]), creators: z.array(z.string()).optional().default([]), + publishers: z.array(z.string()).optional().default([]), }) .optional(), }); @@ -121,6 +122,7 @@ const rawSearchResponseWithAggregationsSchema = rawSearchResponseSchema.merge( locations: rawAggregationSchema, materials: rawAggregationSchema, creators: rawAggregationSchema, + publishers: rawAggregationSchema, }), owners: rawAggregationSchema, types: rawAggregationSchema, @@ -128,6 +130,7 @@ const rawSearchResponseWithAggregationsSchema = rawSearchResponseSchema.merge( locations: rawAggregationSchema, materials: rawAggregationSchema, creators: rawAggregationSchema, + publishers: rawAggregationSchema, }), }) ); @@ -264,6 +267,7 @@ export class HeritageObjectSearcher { locations: buildAggregation(RawKeys.CountryCreated), materials: buildAggregation(RawKeys.Material), creators: buildAggregation(RawKeys.Creator), + publishers: buildAggregation(RawKeys.Publisher), }; const sortByRawKey = sortByToRawKeys.get(options.sortBy!)!; @@ -318,6 +322,7 @@ export class HeritageObjectSearcher { [RawKeys.CountryCreated, options.filters?.locations], [RawKeys.Material, options.filters?.materials], [RawKeys.Creator, options.filters?.creators], + [RawKeys.Publisher, options.filters?.publishers], ]); for (const [rawHeritageObjectKey, filters] of queryFilters) { @@ -374,6 +379,11 @@ export class HeritageObjectSearcher { aggregations.creators.buckets ); + const publisherFilters = buildFilters( + aggregations.all.publishers.buckets, + aggregations.publishers.buckets + ); + const searchResult: SearchResult = { totalCount: hits.total.value, offset: options.offset!, @@ -388,6 +398,7 @@ export class HeritageObjectSearcher { locations: locationFilters, materials: materialFilters, creators: creatorFilters, + publishers: publisherFilters, }, };