Skip to content

Commit

Permalink
added 'creators' facet
Browse files Browse the repository at this point in the history
  • Loading branch information
sdevalk committed Oct 2, 2023
1 parent 9b4caf3 commit a3691d6
Show file tree
Hide file tree
Showing 3 changed files with 60 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 @@ -18,5 +18,6 @@ export type SearchResult = {
subjects: SearchResultFilter[];
locations: SearchResultFilter[];
materials: SearchResultFilter[];
creators: SearchResultFilter[];
};
};
48 changes: 48 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 @@ -371,6 +371,23 @@ describe('search', () => {
name: 'Paper',
},
],
creators: [
{
totalCount: 1,
id: 'Adriaan Boer',
name: 'Adriaan Boer',
},
{
totalCount: 1,
id: 'Geeske van Châtellerault',
name: 'Geeske van Châtellerault',
},
{
totalCount: 1,
id: 'Vincent van Gogh',
name: 'Vincent van Gogh',
},
],
},
});
});
Expand Down Expand Up @@ -492,4 +509,35 @@ describe('search', () => {
},
});
});

it('finds heritage objects if "creators" filter matches', async () => {
const result = await heritageObjectSearcher.search({
filters: {
creators: ['Adriaan Boer'],
},
});

expect(result).toMatchObject({
totalCount: 1,
filters: {
creators: [
{
totalCount: 1,
id: 'Adriaan Boer',
name: 'Adriaan Boer',
},
{
totalCount: 0,
id: 'Geeske van Châtellerault',
name: 'Geeske van Châtellerault',
},
{
totalCount: 0,
id: 'Vincent van Gogh',
name: 'Vincent van Gogh',
},
],
},
});
});
});
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 @@ -61,6 +61,7 @@ const searchOptionsSchema = z.object({
subjects: z.array(z.string()).optional().default([]),
locations: z.array(z.string()).optional().default([]),
materials: z.array(z.string()).optional().default([]),
creators: z.array(z.string()).optional().default([]),
})
.optional(),
});
Expand Down Expand Up @@ -119,12 +120,14 @@ const rawSearchResponseWithAggregationsSchema = rawSearchResponseSchema.merge(
subjects: rawAggregationSchema,
locations: rawAggregationSchema,
materials: rawAggregationSchema,
creators: rawAggregationSchema,
}),
owners: rawAggregationSchema,
types: rawAggregationSchema,
subjects: rawAggregationSchema,
locations: rawAggregationSchema,
materials: rawAggregationSchema,
creators: rawAggregationSchema,
}),
})
);
Expand Down Expand Up @@ -260,6 +263,7 @@ export class HeritageObjectSearcher {
subjects: buildAggregation(RawKeys.About),
locations: buildAggregation(RawKeys.CountryCreated),
materials: buildAggregation(RawKeys.Material),
creators: buildAggregation(RawKeys.Creator),
};

const sortByRawKey = sortByToRawKeys.get(options.sortBy!)!;
Expand Down Expand Up @@ -313,6 +317,7 @@ export class HeritageObjectSearcher {
[RawKeys.About, options.filters?.subjects],
[RawKeys.CountryCreated, options.filters?.locations],
[RawKeys.Material, options.filters?.materials],
[RawKeys.Creator, options.filters?.creators],
]);

for (const [rawHeritageObjectKey, filters] of queryFilters) {
Expand Down Expand Up @@ -364,6 +369,11 @@ export class HeritageObjectSearcher {
aggregations.materials.buckets
);

const creatorFilters = buildFilters(
aggregations.all.creators.buckets,
aggregations.creators.buckets
);

const searchResult: SearchResult = {
totalCount: hits.total.value,
offset: options.offset!,
Expand All @@ -377,6 +387,7 @@ export class HeritageObjectSearcher {
subjects: subjectFilters,
locations: locationFilters,
materials: materialFilters,
creators: creatorFilters,
},
};

Expand Down

0 comments on commit a3691d6

Please sign in to comment.