Skip to content

Commit

Permalink
search-api: Include url to nodes in search
Browse files Browse the repository at this point in the history
  • Loading branch information
jnatten committed Feb 21, 2025
1 parent d56b5e6 commit 92f56b9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ class ArticleApiProperties extends BaseProps with DatabaseProps {
).getOrElse(Environment, "https://h5p.ndla.no")
)

def ndlaFrontendUrl: String = Environment match {
case "local" => "http://localhost:30017"
case "prod" => "https://ndla.no"
case _ => s"https://$Environment.ndla.no"
}

private def BrightcoveAccountId: String = prop("NDLA_BRIGHTCOVE_ACCOUNT_ID")
private def BrightcovePlayerId: String = prop("NDLA_BRIGHTCOVE_PLAYER_ID")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ trait BaseProps {
def TaxonomyUrl: String = s"http://$TaxonomyApiHost"
def disableWarmup: Boolean = booleanPropOrElse("DISABLE_WARMUP", default = false)

def ndlaFrontendUrl: String = Environment match {
case "local" => "http://localhost:30017"
case "prod" => "https://ndla.no"
case _ => s"https://$Environment.ndla.no"
}

def MAX_SEARCH_THREADS: Int = intPropOrDefault("MAX_SEARCH_THREADS", 100)
def SEARCH_INDEX_SHARDS: Int = intPropOrDefault("SEARCH_INDEX_SHARDS", 1)
def SEARCH_INDEX_REPLICAS: Int = intPropOrDefault("SEARCH_INDEX_REPLICAS", 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ object MultiSummaryBaseDTO {
case class NodeHitDTO(
@description("The unique id of the taxonomy node")
id: String,
@description("The title of the taxonomy node")
title: String,
@description("The url to the frontend page of the taxonomy node")
url: Option[String],
@description("Subject page summary if the node is connected to a subject page")
subjectPage: Option[SubjectPageSummaryDTO]
) extends MultiSummaryBaseDTO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ case class SearchableNode(
nodeId: String,
title: SearchableLanguageValues,
contentUri: Option[String],
url: Option[String],
nodeType: NodeType,
subjectPage: Option[SearchableSubjectPage]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,14 @@ trait SearchConverterService {

def nodeHitAsMultiSummary(hit: SearchHit, language: String): Try[NodeHitDTO] = {
val searchableNode = CirceUtil.tryParseAs[SearchableNode](hit.sourceAsString).?
val title = searchableNode.title.getLanguageOrDefault(language).getOrElse("")
val url = searchableNode.url.map(urlPath => s"${props.ndlaFrontendUrl}$urlPath")

Success(
NodeHitDTO(
id = searchableNode.nodeId,
title = title,
url = url,
subjectPage = searchableNode.subjectPage.map(subjectPageToSummary(_, language))
)
)
Expand Down Expand Up @@ -1136,6 +1140,7 @@ trait SearchConverterService {
SearchableNode(
nodeId = node.id,
title = getSearchableLanguageValues(node.name, node.translations),
url = node.url,
contentUri = node.contentUri,
nodeType = node.nodeType,
subjectPage = frontpage
Expand Down

0 comments on commit 92f56b9

Please sign in to comment.