Skip to content

Commit

Permalink
collect on filter->query partial functions to prevent match error
Browse files Browse the repository at this point in the history
  • Loading branch information
kenoir committed Nov 21, 2024
1 parent ae21bd5 commit dcd23a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ class ImagesRequestBuilder()
searchOptions.searchQuery.isDefined || searchOptions.color.isDefined,
includes = Seq("display", "vectorValues.reducedFeatures"),
aggs = filteredAggregationBuilder(pairables).filteredAggregations,
preFilter = unpairables.map(buildImageFilterQuery),
preFilter = unpairables.collect(buildImageFilterQuery),
postFilter = Some(
must(
searchOptions.filters.map(buildImageFilterQuery)
searchOptions.filters.collect(buildImageFilterQuery)
)
),
knn = searchOptions.color.map(ColorQuery(_))
Expand Down Expand Up @@ -111,8 +111,7 @@ class ImagesRequestBuilder()
searchOptions.sortOrder
}

private def buildImageFilterQuery(filter: ImageFilter): Query =
filter match {
private val buildImageFilterQuery: PartialFunction[ImageFilter, Query] = {
case LicenseFilter(licenseIds) =>
termsQuery(
field = "filterableValues.locations.license.id",
Expand All @@ -134,10 +133,10 @@ class ImagesRequestBuilder()
genreLabels
)
case GenreConceptFilter(conceptIds) if conceptIds.nonEmpty =>
termsQuery(
"filterableValues.source.genres.concepts.id",
conceptIds
)
termsQuery(
"filterableValues.source.genres.concepts.id",
conceptIds
)
case SubjectLabelFilter(subjectLabels) =>
termsQuery(
"filterableValues.source.subjects.label",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ object WorksRequestBuilder
sortByScore = searchOptions.searchQuery.isDefined,
includes = Seq("display", "type"),
aggs = filteredAggregationBuilder(pairables).filteredAggregations,
preFilter = (VisibleWorkFilter :: unpairables).map(buildWorkFilterQuery),
preFilter = (VisibleWorkFilter :: unpairables).collect(buildWorkFilterQuery),
postFilter = Some(
must(
pairables.map(buildWorkFilterQuery)
pairables.collect(buildWorkFilterQuery)
)
)
)
Expand Down Expand Up @@ -139,8 +139,7 @@ object WorksRequestBuilder
searchOptions.sortOrder
}

private def buildWorkFilterQuery(workFilter: WorkFilter): Query =
workFilter match {
val buildWorkFilterQuery: PartialFunction[WorkFilter, Query] = {
case VisibleWorkFilter =>
termQuery(field = "type", value = "Visible")
case FormatFilter(formatIds) =>
Expand Down

0 comments on commit dcd23a9

Please sign in to comment.