Skip to content

Commit

Permalink
search-api: Rename Title to HtmlTitle to avoid conflict
Browse files Browse the repository at this point in the history
A little bit more descriptive to avoid conflict with a regular title
object.
  • Loading branch information
jnatten committed Dec 5, 2024
1 parent c2ea283 commit 54ac86a
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import sttp.tapir.Schema.annotations.description
@description("Search result for article api")
case class ArticleResult(
@description("The unique id of this article") id: Long,
@description("The title of the article") title: Title,
@description("The title of the article") title: TitleWithHtml,
@description("The introduction of the article") introduction: Option[ArticleIntroduction],
@description("The type of the article") articleType: String,
@description("List of supported languages") supportedLanguages: Seq[String]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import sttp.tapir.Schema.annotations.description
@description("Search result for audio api")
case class AudioResult(
@description("The unique id of this audio") id: Long,
@description("The title of this audio") title: Title,
@description("The title of this audio") title: TitleWithHtml,
@description("A direct link to the audio") url: String,
@description("List of supported languages") supportedLanguages: Seq[String]
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import sttp.tapir.Schema.annotations.description
@description("Search result for image api")
case class ImageResult(
@description("The unique id of this image") id: Long,
@description("The title of this image") title: Title,
@description("The title of this image") title: TitleWithHtml,
@description("The alt text of this image") altText: ImageAltText,
@description("A direct link to the image") previewUrl: String,
@description("A link to get meta data related to the image") metaUrl: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import sttp.tapir.Schema.annotations.description
@description("Search result for learningpath api")
case class LearningpathResult(
@description("The unique id of this learningpath") id: Long,
@description("The title of the learningpath") title: Title,
@description("The title of the learningpath") title: TitleWithHtml,
@description("The introduction of the learningpath") introduction: LearningPathIntroduction,
@description("List of supported languages") supportedLanguages: Seq[String]
)
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object HighlightedField {
@description("Short summary of information about the resource")
case class MultiSearchSummary(
@description("The unique id of the resource") id: Long,
@description("The title of the resource") title: Title,
@description("The title of the resource") title: TitleWithHtml,
@description("The meta description of the resource") metaDescription: MetaDescription,
@description("The meta image for the resource") metaImage: Option[MetaImage],
@description("Url pointing to the resource") url: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import sttp.tapir.Schema.annotations.description
@description("Title of resource")
case class Title(
@description("The freetext title of the resource") title: String,
@description("The freetext html-version title of the article") htmlTitle: String,
@description("ISO 639-1 code that represents the language used in title") language: String
) extends LanguageField[String] {
override def value: String = title
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Part of NDLA search-api
* Copyright (C) 2018 NDLA
*
* See LICENSE
*/

package no.ndla.searchapi.model.api

import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
import no.ndla.language.model.LanguageField
import sttp.tapir.Schema.annotations.description

@description("Title of resource")
case class TitleWithHtml(
@description("The freetext title of the resource") title: String,
@description("The freetext html-version title of the article") htmlTitle: String,
@description("ISO 639-1 code that represents the language used in title") language: String
) extends LanguageField[String] {
override def value: String = title
override def isEmpty: Boolean = title.isEmpty
}

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

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ trait ConverterService {
private def articleSearchResultToApi(article: ArticleApiSearchResult): api.ArticleResult = {
api.ArticleResult(
article.id,
api.Title(article.title.title, article.title.htmlTitle, article.title.language),
api.TitleWithHtml(article.title.title, article.title.htmlTitle, article.title.language),
article.introduction.map(i => ArticleIntroduction(i.introduction, i.htmlIntroduction, i.language)),
article.articleType,
article.supportedLanguages
Expand All @@ -66,7 +66,7 @@ trait ConverterService {
private def learningpathSearchResultToApi(learningpath: LearningpathApiSearchResult): api.LearningpathResult = {
api.LearningpathResult(
learningpath.id,
api.Title(learningpath.title.title, learningpath.title.title, learningpath.title.language),
api.TitleWithHtml(learningpath.title.title, learningpath.title.title, learningpath.title.language),
LearningPathIntroduction(learningpath.introduction.introduction, learningpath.introduction.language),
learningpath.supportedLanguages
)
Expand All @@ -92,7 +92,7 @@ trait ConverterService {

api.ImageResult(
image.id.toLong,
api.Title(image.title.title, image.title.title, image.title.language),
api.TitleWithHtml(image.title.title, image.title.title, image.title.language),
api.ImageAltText(image.altText.alttext, image.altText.language),
previewUrl.toString,
metaUrl.toString,
Expand All @@ -118,7 +118,7 @@ trait ConverterService {
val url = audio.url.withHost(host).withScheme(scheme).toString
api.AudioResult(
audio.id,
api.Title(audio.title.title, audio.title.title, audio.title.language),
api.TitleWithHtml(audio.title.title, audio.title.title, audio.title.language),
url,
audio.supportedLanguages
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ trait SearchConverterService {

val contexts = filterContexts(searchableArticle.contexts, language, filterInactive)
val titles = searchableArticle.domainObject.title.map(title =>
api.Title(Jsoup.parseBodyFragment(title.title).body().text(), title.title, title.language)
api.TitleWithHtml(Jsoup.parseBodyFragment(title.title).body().text(), title.title, title.language)
)
val introductions = searchableArticle.domainObject.introduction.map(intro =>
api.article
Expand All @@ -611,7 +611,7 @@ trait SearchConverterService {
})

val title =
findByLanguageOrBestEffort(titles, language).getOrElse(api.Title("", "", UnknownLanguage.toString))
findByLanguageOrBestEffort(titles, language).getOrElse(api.TitleWithHtml("", "", UnknownLanguage.toString))
val metaDescription = findByLanguageOrBestEffort(metaDescriptions, language).getOrElse(
api.MetaDescription("", UnknownLanguage.toString)
)
Expand Down Expand Up @@ -657,7 +657,7 @@ trait SearchConverterService {

val contexts = filterContexts(searchableDraft.contexts, language, filterInactive)
val titles = searchableDraft.domainObject.title.map(title =>
api.Title(Jsoup.parseBodyFragment(title.title).body().text(), title.title, title.language)
api.TitleWithHtml(Jsoup.parseBodyFragment(title.title).body().text(), title.title, title.language)
)
val introductions = searchableDraft.domainObject.introduction.map(intro =>
api.article
Expand All @@ -677,7 +677,7 @@ trait SearchConverterService {
})

val title =
findByLanguageOrBestEffort(titles, language).getOrElse(api.Title("", "", UnknownLanguage.toString))
findByLanguageOrBestEffort(titles, language).getOrElse(api.TitleWithHtml("", "", UnknownLanguage.toString))
val metaDescription = findByLanguageOrBestEffort(metaDescriptions, language).getOrElse(
api.MetaDescription("", UnknownLanguage.toString)
)
Expand Down Expand Up @@ -731,7 +731,8 @@ trait SearchConverterService {
val searchableLearningPath = CirceUtil.unsafeParseAs[SearchableLearningPath](hit.sourceAsString)

val contexts = filterContexts(searchableLearningPath.contexts, language, filterInactive)
val titles = searchableLearningPath.title.languageValues.map(lv => api.Title(lv.value, lv.value, lv.language))
val titles =
searchableLearningPath.title.languageValues.map(lv => api.TitleWithHtml(lv.value, lv.value, lv.language))
val metaDescriptions =
searchableLearningPath.description.languageValues.map(lv => api.MetaDescription(lv.value, lv.language))
val tags =
Expand All @@ -740,7 +741,7 @@ trait SearchConverterService {
val supportedLanguages = getSupportedLanguages(titles, metaDescriptions, tags)

val title =
findByLanguageOrBestEffort(titles, language).getOrElse(api.Title("", "", UnknownLanguage.toString))
findByLanguageOrBestEffort(titles, language).getOrElse(api.TitleWithHtml("", "", UnknownLanguage.toString))
val metaDescription = findByLanguageOrBestEffort(metaDescriptions, language).getOrElse(
api.MetaDescription("", UnknownLanguage.toString)
)
Expand Down Expand Up @@ -788,15 +789,16 @@ trait SearchConverterService {
def conceptHitAsMultiSummary(hit: SearchHit, language: String): MultiSearchSummary = {
val searchableConcept = CirceUtil.unsafeParseAs[SearchableConcept](hit.sourceAsString)

val titles = searchableConcept.title.languageValues.map(lv => api.Title(lv.value, lv.value, lv.language))
val titles = searchableConcept.title.languageValues.map(lv => api.TitleWithHtml(lv.value, lv.value, lv.language))

val content = searchableConcept.content.languageValues.map(lv => api.MetaDescription(lv.value, lv.language))
val tags = searchableConcept.tags.languageValues.map(lv => Tag(lv.value, lv.language))

val supportedLanguages = getSupportedLanguages(titles, content, tags)

val title = findByLanguageOrBestEffort(titles, language).getOrElse(api.Title("", "", UnknownLanguage.toString))
val url = s"${props.ExternalApiUrls("concept-api")}/${searchableConcept.id}"
val title =
findByLanguageOrBestEffort(titles, language).getOrElse(api.TitleWithHtml("", "", UnknownLanguage.toString))
val url = s"${props.ExternalApiUrls("concept-api")}/${searchableConcept.id}"
val metaImages = searchableConcept.domainObject.metaImage.map(image => {
val metaImageUrl = s"${props.ExternalApiUrls("raw-image")}/${image.imageId}"
api.MetaImage(metaImageUrl, image.altText, image.language)
Expand Down

0 comments on commit 54ac86a

Please sign in to comment.