Skip to content

Commit

Permalink
Show Other repository type as Repository in search index
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-lamed committed Dec 27, 2024
1 parent ba554d1 commit ee40b9f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions app/uk/gov/hmrc/cataloguefrontend/search/SearchIndex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import uk.gov.hmrc.cataloguefrontend.leakdetection.routes as leakRoutes
import uk.gov.hmrc.cataloguefrontend.model.{Environment, ServiceName}
import uk.gov.hmrc.cataloguefrontend.prcommenter.{PrCommenterConnector, routes as prcommenterRoutes}
import uk.gov.hmrc.cataloguefrontend.repository.routes as reposRoutes
import uk.gov.hmrc.cataloguefrontend.search.SearchIndex.{normalizeTerm, optimizeIndex}
import uk.gov.hmrc.cataloguefrontend.serviceconfigs.routes as serviceConfigsRoutes
import uk.gov.hmrc.cataloguefrontend.servicecommissioningstatus.routes as commissioningRoutes
import uk.gov.hmrc.cataloguefrontend.shuttering.{ShutterType, routes as shutterRoutes}
Expand All @@ -48,10 +47,10 @@ case class SearchTerm(
link : String,
weight : Float = 0.5f,
hints : Set[String] = Set.empty,
openInNewWindow: Boolean = false
openInNewWindow: Boolean = false
):
lazy val terms: Set[String] =
Set(name, linkType).union(hints).map(normalizeTerm)
Set(name, linkType).union(hints).map(SearchIndex.normalizeTerm)

@Singleton
class SearchIndex @Inject()(
Expand All @@ -61,6 +60,8 @@ class SearchIndex @Inject()(
userManagementConnector : UserManagementConnector
)(using ExecutionContext):

import SearchIndex.*

private[search] val cachedIndex =
AtomicReference[Map[String, Seq[SearchTerm]]](Map.empty)

Expand Down Expand Up @@ -95,7 +96,7 @@ class SearchIndex @Inject()(
teams <- teamsAndRepositoriesConnector.allTeams()
teamPageLinks = teams.flatMap(t => List(SearchTerm("teams", t.name.asString, teamRoutes.TeamsController.team(t.name).url, 0.5f),
SearchTerm("deployments", t.name.asString, s"${wrwRoutes.WhatsRunningWhereController.releases().url}?profile_type=team&profile_name=${URLEncoder.encode(t.name.asString, "UTF-8")}")))
repoLinks = repos.flatMap(r => List(SearchTerm(r.repoType.asString, r.name, catalogueRoutes.CatalogueController.repository(r.name).url, 0.5f, Set("repository")),
repoLinks = repos.flatMap(r => List(SearchTerm(repoTypeString(r.repoType), r.name, catalogueRoutes.CatalogueController.repository(r.name).url, 0.5f, Set("repository")),
SearchTerm("health", r.name, healthRoutes.HealthIndicatorsController.breakdownForRepo(r.name).url),
SearchTerm("leak", r.name, leakRoutes.LeakDetectionController.branchSummaries(r.name).url, 0.5f)))
serviceLinks = repos.filter(_.repoType == RepoType.Service)
Expand All @@ -122,6 +123,11 @@ object SearchIndex:
def normalizeTerm(term: String): String =
term.toLowerCase.replaceAll(" -_", "")

private[search] def repoTypeString(repoType: RepoType): String =
repoType match
case RepoType.Other => "Repository"
case _ => repoType.asString

private[search] def search(
query: Seq[String],
index: Map[String, Seq[SearchTerm]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h1 class="page-heading mt-4">Teams</h1>

<div id="teams-list">
<div class="row">
<form action="@teamsRoutes.TeamsController.allTeams" method="get">
<form action="@teamsRoutes.TeamsController.allTeams()" method="get">
<div class="row mb-3">
<label for="search" class="col-1 col-form-label fw-bold">Team:</label>
<div class="col-5">
Expand Down

0 comments on commit ee40b9f

Please sign in to comment.