Skip to content

Commit

Permalink
Apply auto-formatting rules
Browse files Browse the repository at this point in the history
  • Loading branch information
weco-bot committed Nov 22, 2024
1 parent 2cfc7d5 commit ed71af6
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 23 deletions.
14 changes: 7 additions & 7 deletions search/src/main/scala/weco/api/search/models/Aggregation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ object AggregationMapping {
// the value of that field as an array of Buckets"
private val globalAggBuckets = root.each.buckets.each.as[RawAggregationBucket]
// This optic does the same for buckets within the self aggregation
private val selfAggBuckets = root.self.each.buckets.each.as[RawAggregationBucket]
private val selfAggBuckets =
root.self.each.buckets.each.as[RawAggregationBucket]

// When we use the self aggregation pattern, buckets are returned
// in aggregations at multiple depths. This will return
Expand Down Expand Up @@ -59,15 +60,16 @@ object AggregationMapping {

def aggregationParser(
jsonString: String
): Try[Aggregation] = {
): Try[Aggregation] =
parse(jsonString)
.map(bucketsFromAnywhere)
.toTry
.map(buckets =>
buckets.map { bucket =>
// Each ID-based aggregation bucket contain a list of label-based sub-aggregation buckets,
// storing a list of labels associated with a given ID.
val labelBucketsOption = bucket.labelSubAggregation.map(_.hcursor.downField("buckets").as[Seq[LabelBucket]])
val labelBucketsOption = bucket.labelSubAggregation.map(
_.hcursor.downField("buckets").as[Seq[LabelBucket]])

// Retrieve the label from the first bucket. There might be multiple labels associated with a given ID,
// but we only want to expose the most commonly used one to the frontend.
Expand All @@ -83,13 +85,11 @@ object AggregationMapping {
val label = firstLabelBucket.map(_.key).getOrElse(key)

AggregationBucket(
data = AggregationBucketData(id=key, label),
data = AggregationBucketData(id = key, label),
count = bucket.count
)
}
)
})
.map(buckets => Aggregation(buckets.toList))
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait ElasticAggregations extends Logging {
}

implicit class EnhancedEsAggregations(aggregations: Elastic4sAggregations) {
def decodeAgg(name: String): Option[Aggregation] = {
def decodeAgg(name: String): Option[Aggregation] =
aggregations
.getAgg(name)
.flatMap(
Expand All @@ -28,6 +28,5 @@ trait ElasticAggregations extends Logging {
Failure(err)
}.toOption
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ object WorkAggregations extends ElasticAggregations {
languages = e4sAggregations.decodeAgg("languages"),
subjectsLabel = e4sAggregations.decodeAgg("subjects"),
// TODO decode only agents here once `contributors` is removed
contributorsAgentsLabel =
e4sAggregations.decodeAgg("contributors"),
contributorsAgentsLabel = e4sAggregations.decodeAgg("contributors"),
itemsLocationsLicense = e4sAggregations.decodeAgg("license"),
availabilities = e4sAggregations.decodeAgg("availabilities")
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package weco.api.search.models.display

import io.circe.generic.extras.JsonKey
import weco.api.search.models.{Aggregation, AggregationBucket, AggregationBucketData}
import weco.api.search.models.{
Aggregation,
AggregationBucket,
AggregationBucketData
}

case class DisplayAggregation(
buckets: List[DisplayAggregationBucket],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package weco.api.search.models.display

import weco.api.search.models.{AggregationBucket, AvailabilitiesFilter, ContributorsFilter, DocumentFilter, FormatFilter, GenreFilter, LanguagesFilter, LicenseFilter, SubjectLabelFilter}
import weco.api.search.models.{
AggregationBucket,
AvailabilitiesFilter,
ContributorsFilter,
DocumentFilter,
FormatFilter,
GenreFilter,
LanguagesFilter,
LicenseFilter,
SubjectLabelFilter
}

trait FilterAggregationMatcher {
def matchBucket(bucketData: AggregationBucket): Boolean
}

case class AggregationDataLabelInFilter(labels: Seq[String])
extends FilterAggregationMatcher {
def matchBucket(bucket: AggregationBucket): Boolean = {
def matchBucket(bucket: AggregationBucket): Boolean =
labels.contains(bucket.data.label)
}
}

case class AggregationDataIdInFilter(labels: Seq[String])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ object WorksRequestBuilder
"productionDates",
"aggregatableValues.production.dates",
size = 10
)
.minDocCount(1)
).minDocCount(1)

case WorkAggregationRequest.Genre =>
toIdBasedAggregation("genres", "aggregatableValues.genres", size = 20)
Expand All @@ -119,7 +118,10 @@ object WorksRequestBuilder
)

case WorkAggregationRequest.Languages =>
toIdBasedAggregation("languages", "aggregatableValues.languages", size = 200)
toIdBasedAggregation(
"languages",
"aggregatableValues.languages",
size = 200)

// Note: we want these aggregations to return every possible value, so we
// want this to be as many licenses as we support in the catalogue pipeline.
Expand All @@ -146,11 +148,12 @@ object WorksRequestBuilder
)
}

private def dateOrder(implicit
searchOptions: WorkSearchOptions
): Option[SortingOrder] =
searchOptions.sortBy collectFirst { case ProductionDateSortRequest =>
searchOptions.sortOrder
private def dateOrder(
implicit
searchOptions: WorkSearchOptions): Option[SortingOrder] =
searchOptions.sortBy collectFirst {
case ProductionDateSortRequest =>
searchOptions.sortOrder
}

private def buildWorkFilterQuery(filters: Seq[WorkFilter]): Seq[Query] =
Expand Down

0 comments on commit ed71af6

Please sign in to comment.