Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove references to _queryType #654

Merged
merged 2 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions search/src/main/scala/weco/api/search/models/SearchQuery.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
package weco.api.search.models

case class SearchQuery(query: String, queryType: SearchQueryType)
object SearchQuery {
def apply(
query: String,
maybeQueryType: Option[SearchQueryType]
): SearchQuery =
SearchQuery(query, maybeQueryType.getOrElse(SearchQueryType.default))

def apply(query: String): SearchQuery =
SearchQuery(query, None)
}
case class SearchQuery(query: String)

This file was deleted.

12 changes: 1 addition & 11 deletions search/src/main/scala/weco/api/search/rest/WorksParams.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ case class MultipleWorksParams(
include: Option[WorksIncludes],
aggregations: Option[List[WorkAggregationRequest]],
query: Option[String],
_queryType: Option[SearchQueryType]
) extends QueryParams
with Paginated {

Expand All @@ -102,7 +101,7 @@ case class MultipleWorksParams(
def searchOptions(apiConfig: ApiConfig): WorkSearchOptions =
WorkSearchOptions(
searchQuery = query map { query =>
SearchQuery(query, _queryType)
SearchQuery(query)
},
filters = filters,
pageSize = pageSize.getOrElse(apiConfig.defaultPageSize),
Expand Down Expand Up @@ -163,7 +162,6 @@ object MultipleWorksParams extends QueryParamsUtils {
"pageSize".as[Int].?,
"sort".as[List[SortRequest]].?,
"sortOrder".as[SortingOrder].?,
"_queryType".as[SearchQueryType].?,
"query".as[String].?,
"include".as[WorksIncludes].?,
"aggregations".as[List[WorkAggregationRequest]].?
Expand All @@ -178,7 +176,6 @@ object MultipleWorksParams extends QueryParamsUtils {
pageSize,
sort,
sortOrder,
queryType,
query,
includes,
aggregations
Expand Down Expand Up @@ -246,7 +243,6 @@ object MultipleWorksParams extends QueryParamsUtils {
include = includes,
aggregations = aggregations,
query = query,
_queryType = queryType
)
validated(params.paginationErrors, params)
}
Expand Down Expand Up @@ -311,10 +307,4 @@ object MultipleWorksParams extends QueryParamsUtils {
"asc" -> SortingOrder.Ascending,
"desc" -> SortingOrder.Descending
)

implicit val _queryTypeDecoder: Decoder[SearchQueryType] =
decodeOneWithDefaultOf(
SearchQueryType.default,
"MultiMatcher" -> SearchQueryType.MultiMatcher
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import weco.api.search.models.request.{
WorkAggregationRequest
}
import weco.api.search.rest.PaginationQuery
import weco.api.search.elasticsearch.WorksMultiMatcher

object WorksRequestBuilder
extends ElasticsearchRequestBuilder[WorkSearchOptions] {
Expand Down Expand Up @@ -128,8 +129,8 @@ object WorksRequestBuilder
): BoolQuery =
searchOptions.searchQuery
.map {
case SearchQuery(query, queryType) =>
queryType.toEsQuery(query)
case SearchQuery(query) =>
WorksMultiMatcher(query)
}
.getOrElse { boolQuery }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.scalatest.EitherValues
import weco.api.search.fixtures.{IndexFixtures, TestDocumentFixtures}
import weco.api.search.generators.SearchOptionsGenerators
import weco.api.search.models.index.IndexedWork
import weco.api.search.models.{SearchQuery, SearchQueryType}
import weco.api.search.models.{SearchQuery}
import weco.api.search.services.WorksService
import weco.fixtures.TestWith

Expand Down Expand Up @@ -246,21 +246,19 @@ class WorksQueryTest

private def assertForQueryResults[R](index: Index, query: String)(
testWith: TestWith[Seq[IndexedWork.Visible], R]
) = SearchQueryType.allowed map { queryType =>
) = {
val future = worksService.listOrSearch(
index,
searchOptions = createWorksSearchOptionsWith(
searchQuery = Some(SearchQuery(query, queryType))
searchQuery = Some(SearchQuery(query))
)
)

val results = whenReady(future) {
_.right.value.results
}

withClue(s"[Using query: ${queryType.name}]") {
testWith(results)
}
testWith(results)
}

private val worksService = new WorksService(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,6 @@ class WorksErrorsTest extends ApiWorksTestBase with TableDrivenPropertyChecks {
}
}

// This is expected as it's transient parameter that will have valid values changing over time
// And if there is a client with a deprecated value, we wouldn't want it to fail
describe("returns a 200 for invalid values in the ?_queryType parameter") {
it("200s despite being a unknown value") {
withWorksApi {
case (_, route) =>
assertJsonResponse(
route,
path =
s"$rootPath/works?_queryType=athingwewouldneverusebutmightbecausewesaidwewouldnot"
) {
Status.OK -> emptyJsonResult
}
}
}
}

describe("returns a 400 Bad Request for user errors") {
describe("errors in the ?pageSize query") {
it("not an integer") {
Expand Down Expand Up @@ -296,7 +279,7 @@ class WorksErrorsTest extends ApiWorksTestBase with TableDrivenPropertyChecks {
case (_, route) =>
assertBadRequest(route)(
path =
s"$rootPath/works?_queryType=undefined&production.dates.from=%2B011860-01-01",
s"$rootPath/works?production.dates.from=%2B011860-01-01",
description = "production.dates.from: year must be less than 9999"
)
}
Expand Down