Skip to content

Commit

Permalink
Merge pull request #259 from colonial-heritage/feat-objects-facet-loc…
Browse files Browse the repository at this point in the history
…ations

feat: locations facet
  • Loading branch information
sdevalk authored Oct 2, 2023
2 parents 9056469 + 9c88107 commit 29d9a1c
Show file tree
Hide file tree
Showing 3 changed files with 30 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 @@ -16,5 +16,6 @@ export type SearchResult = {
owners: SearchResultFilter[];
types: SearchResultFilter[];
subjects: SearchResultFilter[];
locations: SearchResultFilter[];
};
};
17 changes: 17 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 @@ -332,6 +332,23 @@ describe('search', () => {
name: 'Palace',
},
],
locations: [
{
totalCount: 2,
id: 'Indonesia',
name: 'Indonesia',
},
{
totalCount: 1,
id: 'Malaysia',
name: 'Malaysia',
},
{
totalCount: 1,
id: 'Suriname',
name: 'Suriname',
},
],
},
});
});
Expand Down
12 changes: 12 additions & 0 deletions apps/researcher/src/lib/api/objects/searcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum RawKeys {
Owner = 'https://colonialcollections nl/schema#owner',
Publisher = 'https://colonialcollections nl/schema#publisher',
DateCreated = 'https://colonialcollections nl/schema#dateCreatedStart', // Earliest date of creation
CountryCreated = 'https://colonialcollections nl/schema#countryCreated',
IsPartOf = 'https://colonialcollections nl/schema#isPartOf',
}

Expand All @@ -59,6 +60,7 @@ const searchOptionsSchema = z.object({
owners: z.array(z.string()).optional().default([]),
types: z.array(z.string()).optional().default([]),
subjects: z.array(z.string()).optional().default([]),
locations: z.array(z.string()).optional().default([]),
})
.optional(),
});
Expand Down Expand Up @@ -116,10 +118,12 @@ const rawSearchResponseWithAggregationsSchema = rawSearchResponseSchema.merge(
owners: rawAggregationSchema,
types: rawAggregationSchema,
subjects: rawAggregationSchema,
locations: rawAggregationSchema,
}),
owners: rawAggregationSchema,
types: rawAggregationSchema,
subjects: rawAggregationSchema,
locations: rawAggregationSchema,
}),
})
);
Expand Down Expand Up @@ -253,6 +257,7 @@ export class HeritageObjectSearcher {
owners: buildAggregation(RawKeys.Owner),
types: buildAggregation(RawKeys.AdditionalType),
subjects: buildAggregation(RawKeys.About),
locations: buildAggregation(RawKeys.CountryCreated),
};

const sortByRawKey = sortByToRawKeys.get(options.sortBy!)!;
Expand Down Expand Up @@ -304,6 +309,7 @@ export class HeritageObjectSearcher {
[RawKeys.Owner, options.filters?.owners],
[RawKeys.AdditionalType, options.filters?.types],
[RawKeys.About, options.filters?.subjects],
[RawKeys.CountryCreated, options.filters?.locations],
]);

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

const locationFilters = buildFilters(
aggregations.all.locations.buckets,
aggregations.locations.buckets
);

const searchResult: SearchResult = {
totalCount: hits.total.value,
offset: options.offset!,
Expand All @@ -356,6 +367,7 @@ export class HeritageObjectSearcher {
owners: ownerFilters,
types: typeFilters,
subjects: subjectFilters,
locations: locationFilters,
},
};

Expand Down

2 comments on commit 29d9a1c

@vercel
Copy link

@vercel vercel bot commented on 29d9a1c Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 29d9a1c Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.