-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
search-api: Add grep code indexing and search
This patch introduces `POST /search-api/v1/search/grep`. A new endpoint that can be used to search all the indexed grep codes by prefix, query and a direct code filter.
- Loading branch information
Showing
28 changed files
with
848 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
search-api/src/main/scala/no/ndla/searchapi/controller/parameters/GrepSearchInput.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Part of NDLA search-api | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
* | ||
*/ | ||
|
||
package no.ndla.searchapi.controller.parameters | ||
|
||
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} | ||
import io.circe.{Decoder, Encoder} | ||
import no.ndla.network.tapir.NonEmptyString | ||
import no.ndla.searchapi.model.api.grep.GrepSort | ||
import sttp.tapir.Schema.annotations.description | ||
|
||
// format: off | ||
@description("Input parameters to subject aggregations endpoint") | ||
case class GrepSearchInput( | ||
@description("A comma separated list of prefixes that should be returned in the search.") | ||
prefixFilter: Option[List[String]], | ||
|
||
@description("A comma separated list of codes that should be returned in the search.") | ||
codes: Option[List[String]], | ||
|
||
@description("A query to filter the query by.") | ||
query: Option[NonEmptyString], | ||
|
||
@description("The page number of the search hits to display.") | ||
page: Option[Int], | ||
|
||
@description(s"The number of search hits to display for each page.") | ||
pageSize: Option[Int], | ||
|
||
@description("The sort order of the search hits.") | ||
sort: Option[GrepSort], | ||
|
||
@description("The ISO 639-1 language code describing language used in query-params") | ||
language: Option[String] | ||
) | ||
|
||
object GrepSearchInput { | ||
implicit val encoder: Encoder[GrepSearchInput] = deriveEncoder | ||
implicit val decoder: Decoder[GrepSearchInput] = deriveDecoder | ||
} |
25 changes: 25 additions & 0 deletions
25
search-api/src/main/scala/no/ndla/searchapi/model/api/grep/GrepResult.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Part of NDLA search-api | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
* | ||
*/ | ||
|
||
package no.ndla.searchapi.model.api.grep | ||
|
||
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} | ||
import io.circe.{Decoder, Encoder} | ||
import no.ndla.searchapi.model.api.Title | ||
import sttp.tapir.Schema.annotations.description | ||
|
||
@description("Information about a single grep search result entry") | ||
case class GrepResult( | ||
@description("The grep code") code: String, | ||
@description("The greps title") title: Title | ||
) | ||
|
||
object GrepResult { | ||
implicit val encoder: Encoder[GrepResult] = deriveEncoder | ||
implicit val decoder: Decoder[GrepResult] = deriveDecoder | ||
} |
27 changes: 27 additions & 0 deletions
27
search-api/src/main/scala/no/ndla/searchapi/model/api/grep/GrepSearchResults.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Part of NDLA search-api | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
* | ||
*/ | ||
|
||
package no.ndla.searchapi.model.api.grep | ||
|
||
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} | ||
import io.circe.{Decoder, Encoder} | ||
import sttp.tapir.Schema.annotations.description | ||
|
||
@description("Information about search-results") | ||
case class GrepSearchResults( | ||
@description("The total number of resources matching this query") totalCount: Long, | ||
@description("For which page results are shown from") page: Int, | ||
@description("The number of results per page") pageSize: Int, | ||
@description("The chosen search language") language: String, | ||
@description("The search results") results: Seq[GrepResult] | ||
) | ||
|
||
object GrepSearchResults { | ||
implicit val encoder: Encoder[GrepSearchResults] = deriveEncoder | ||
implicit val decoder: Decoder[GrepSearchResults] = deriveDecoder | ||
} |
35 changes: 35 additions & 0 deletions
35
search-api/src/main/scala/no/ndla/searchapi/model/api/grep/GrepSort.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Part of NDLA search-api | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
* | ||
*/ | ||
|
||
package no.ndla.searchapi.model.api.grep | ||
|
||
import com.scalatsi.TypescriptType.{TSLiteralString, TSUnion} | ||
import com.scalatsi.{TSNamedType, TSType} | ||
import enumeratum.* | ||
import sttp.tapir.Codec.PlainCodec | ||
import sttp.tapir.Schema | ||
import sttp.tapir.codec.enumeratum.* | ||
|
||
sealed abstract class GrepSort(override val entryName: String) extends EnumEntry | ||
object GrepSort extends Enum[GrepSort] with CirceEnum[GrepSort] { | ||
val values: IndexedSeq[GrepSort] = findValues | ||
val all: Seq[String] = values.map(_.entryName) | ||
|
||
case object ByRelevanceDesc extends GrepSort("-relevance") | ||
case object ByRelevanceAsc extends GrepSort("relevance") | ||
case object ByTitleDesc extends GrepSort("-title") | ||
case object ByTitleAsc extends GrepSort("title") | ||
case object ByCodeDesc extends GrepSort("-code") | ||
case object ByCodeAsc extends GrepSort("code") | ||
|
||
implicit val schema: Schema[GrepSort] = schemaForEnumEntry[GrepSort] | ||
implicit val codec: PlainCodec[GrepSort] = plainCodecEnumEntry[GrepSort] | ||
implicit val enumTsType: TSNamedType[GrepSort] = | ||
TSType.alias[GrepSort]("GrepSort", TSUnion(all.map(s => TSLiteralString(s)))) | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
search-api/src/main/scala/no/ndla/searchapi/model/search/SearchPagination.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Part of NDLA search-api | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
* | ||
*/ | ||
|
||
package no.ndla.searchapi.model.search | ||
|
||
case class SearchPagination( | ||
page: Int, | ||
pageSize: Int, | ||
startAt: Int | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.