Skip to content

Commit

Permalink
added 'publishers' facet
Browse files Browse the repository at this point in the history
  • Loading branch information
sdevalk committed Oct 2, 2023
1 parent a3691d6 commit 5035992
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/researcher/src/lib/api/objects/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ export type SearchResult = {
locations: SearchResultFilter[];
materials: SearchResultFilter[];
creators: SearchResultFilter[];
publishers: SearchResultFilter[];
};
};
68 changes: 68 additions & 0 deletions apps/researcher/src/lib/api/objects/searcher.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
],
},
});
});
Expand Down Expand Up @@ -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',
},
],
},
});
});
});
11 changes: 11 additions & 0 deletions apps/researcher/src/lib/api/objects/searcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});
Expand Down Expand Up @@ -121,13 +122,15 @@ const rawSearchResponseWithAggregationsSchema = rawSearchResponseSchema.merge(
locations: rawAggregationSchema,
materials: rawAggregationSchema,
creators: rawAggregationSchema,
publishers: rawAggregationSchema,
}),
owners: rawAggregationSchema,
types: rawAggregationSchema,
subjects: rawAggregationSchema,
locations: rawAggregationSchema,
materials: rawAggregationSchema,
creators: rawAggregationSchema,
publishers: rawAggregationSchema,
}),
})
);
Expand Down Expand Up @@ -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!)!;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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!,
Expand All @@ -388,6 +398,7 @@ export class HeritageObjectSearcher {
locations: locationFilters,
materials: materialFilters,
creators: creatorFilters,
publishers: publisherFilters,
},
};

Expand Down

0 comments on commit 5035992

Please sign in to comment.