Skip to content

Commit

Permalink
search: Add DTO suffix to all DTO types
Browse files Browse the repository at this point in the history
  • Loading branch information
jnatten committed Dec 10, 2024
1 parent f2b04de commit 01c9851
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package no.ndla.conceptapi.model.api

import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
import no.ndla.search.api.MultiSearchTermsAggregation
import no.ndla.search.api.MultiSearchTermsAggregationDTO
import sttp.tapir.Schema.annotations.description

@description("Information about search-results")
Expand All @@ -19,7 +19,7 @@ case class ConceptSearchResultDTO(
@description("The number of results per page") pageSize: Int,
@description("The chosen search language") language: String,
@description("The search results") results: Seq[ConceptSummaryDTO],
@description("The aggregated fields if specified in query") aggregations: Seq[MultiSearchTermsAggregation]
@description("The aggregated fields if specified in query") aggregations: Seq[MultiSearchTermsAggregationDTO]
)

object ConceptSearchResultDTO {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package no.ndla.searchapi.model.api

import io.circe.{Decoder, Encoder}
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import no.ndla.search.api.MultiSearchTermsAggregation
import no.ndla.search.api.MultiSearchTermsAggregationDTO
import sttp.tapir.Schema.annotations.description

@description("Search result for group search")
Expand All @@ -20,7 +20,7 @@ case class GroupSearchResult(
@description("The chosen search language") language: String,
@description("The search results") results: Seq[MultiSearchSummary],
@description("The suggestions for other searches") suggestions: Seq[MultiSearchSuggestion],
@description("The aggregated fields if specified in query") aggregations: Seq[MultiSearchTermsAggregation],
@description("The aggregated fields if specified in query") aggregations: Seq[MultiSearchTermsAggregationDTO],
@description("Type of resources in this object") resourceType: String
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package no.ndla.searchapi.model.api

import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
import no.ndla.search.api.MultiSearchTermsAggregation
import no.ndla.search.api.MultiSearchTermsAggregationDTO
import sttp.tapir.Schema.annotations.description

@description("Information about search-results")
Expand All @@ -20,7 +20,7 @@ case class MultiSearchResult(
@description("The chosen search language") language: String,
@description("The search results") results: Seq[MultiSearchSummary],
@description("The suggestions for other searches") suggestions: Seq[MultiSearchSuggestion],
@description("The aggregated fields if specified in query") aggregations: Seq[MultiSearchTermsAggregation]
@description("The aggregated fields if specified in query") aggregations: Seq[MultiSearchTermsAggregationDTO]
)

object MultiSearchResult {
Expand Down
8 changes: 4 additions & 4 deletions search/src/main/scala/no/ndla/search/AggregationBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.sksamuel.elastic4s.fields.{ElasticField, NestedField, ObjectField, Te
import com.sksamuel.elastic4s.requests.mappings.MappingDefinition
import com.sksamuel.elastic4s.requests.searches.SearchResponse
import com.sksamuel.elastic4s.requests.searches.aggs.Aggregation
import no.ndla.search.api.{MultiSearchTermsAggregation, TermValue}
import no.ndla.search.api.{MultiSearchTermsAggregationDTO, TermValueDTO}
import no.ndla.search.model.domain.{Bucket, TermAggregation}

import scala.annotation.tailrec
Expand Down Expand Up @@ -143,13 +143,13 @@ object AggregationBuilder {
}
}

def toApiMultiTermsAggregation(agg: TermAggregation): MultiSearchTermsAggregation =
MultiSearchTermsAggregation(
def toApiMultiTermsAggregation(agg: TermAggregation): MultiSearchTermsAggregationDTO =
MultiSearchTermsAggregationDTO(
field = agg.field.mkString("."),
sumOtherDocCount = agg.sumOtherDocCount,
docCountErrorUpperBound = agg.docCountErrorUpperBound,
values = agg.buckets.map(b =>
TermValue(
TermValueDTO(
value = b.value,
count = b.count
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,31 @@ import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
import sttp.tapir.Schema.annotations.description

// format: off
@description("Value that appears in the search aggregation")
case class TermValue(
case class TermValueDTO(
@description("Value that appeared in result") value: String,
@description("Number of times the value appeared in result") count: Int
)

object TermValue {
implicit val encoder: Encoder[TermValue] = deriveEncoder
implicit val decoder: Decoder[TermValue] = deriveDecoder
object TermValueDTO {
implicit val encoder: Encoder[TermValueDTO] = deriveEncoder
implicit val decoder: Decoder[TermValueDTO] = deriveDecoder
}

// format: off
@description("Information about search aggregation on `field`")
case class MultiSearchTermsAggregation(
@description("The field the specific aggregation is matching") field: String,
@description("Number of documents with values that didn't appear in the aggregation. (Will only happen if there are more than 50 different values)") sumOtherDocCount: Int,
case class MultiSearchTermsAggregationDTO(
@description("The field the specific aggregation is matching")
field: String,
@description("Number of documents with values that didn't appear in the aggregation. (Will only happen if there are more than 50 different values)")
sumOtherDocCount: Int,
@description("The result is approximate, this gives an approximation of potential errors. (Specifics here: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-approximate-counts)")
docCountErrorUpperBound: Int,
@description("Values appearing in the field") values: Seq[TermValue]
@description("Values appearing in the field") values: Seq[TermValueDTO]
)
// format: on

object MultiSearchTermsAggregation {
implicit val encoder: Encoder[MultiSearchTermsAggregation] = deriveEncoder
implicit val decoder: Decoder[MultiSearchTermsAggregation] = deriveDecoder
object MultiSearchTermsAggregationDTO {
implicit val encoder: Encoder[MultiSearchTermsAggregationDTO] = deriveEncoder
implicit val decoder: Decoder[MultiSearchTermsAggregationDTO] = deriveDecoder
}

0 comments on commit 01c9851

Please sign in to comment.