Skip to content

Commit

Permalink
Support exact match for clock increment in Game search
Browse files Browse the repository at this point in the history
  • Loading branch information
lenguyenthanh committed Jun 10, 2024
1 parent bfa2e36 commit bbe2f68
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions modules/api/src/main/smithy/search.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ structure Game {
whiteUser: String
blackUser: String
clockInit: Integer
clockInc: Integer
}

structure IntRange {
Expand Down
3 changes: 2 additions & 1 deletion modules/app/src/test/scala/IntegrationSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,5 @@ object IntegrationSuite extends IOSuite:
c <- service.search(Query.game(), 0, 12)
d <- service.search(Query.game(duration = IntRange(a = 99.some, b = 101.some).some), 0, 12)
e <- service.search(Query.game(clockInit = 100.some), 0, 12)
yield expect(a.hitIds.size == 1 && b == a && c == a && d == a && e == a)
f <- service.search(Query.game(clockInc = 200.some), 0, 12)
yield expect(a.hitIds.size == 1 && b == a && c == a && d == a && e == a && f == a)
13 changes: 9 additions & 4 deletions modules/core/src/main/scala/game.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ case class Game(
analysed: Option[Boolean] = None,
whiteUser: Option[String] = None,
blackUser: Option[String] = None,
clockInit: Option[Int] = None
clockInit: Option[Int] = None,
clockInc: Option[Int] = None
)

object Fields:
Expand Down Expand Up @@ -110,6 +111,10 @@ object GameQuery:

def clockInit =
query.clockInit.fold(clock.init.queries(Fields.clockInit))(termsQuery(Fields.clockInit, _).pure[List])

def clockInc =
query.clockInc.fold(clock.inc.queries(Fields.clockInc))(termsQuery(Fields.clockInc, _).pure[List])

List(
usernames.map(termQuery(Fields.uids, _)),
toQueries(winner, Fields.winner),
Expand All @@ -118,18 +123,18 @@ object GameQuery:
turns.queries(Fields.turns),
averageRating.queries(Fields.averageRating),
duration.queries(Fields.duration),
clock.inc.queries(Fields.clockInc),
date.map(Date.formatter.print).queries(Fields.date),
hasAiQueries,
hasAi.getOrElse(true).fold(aiLevel.queries(Fields.ai), Nil),
perf.nonEmpty.fold(List(termsQuery(Fields.perf, perf)), Nil),
clockInit,
clockInc,
toQueries(source, Fields.source),
toQueries(rated, Fields.rated),
toQueries(status, Fields.status),
toQueries(analysed, Fields.analysed),
toQueries(whiteUser, Fields.whiteUser),
toQueries(blackUser, Fields.blackUser),
clockInit
toQueries(blackUser, Fields.blackUser)
).flatten.compile

case class Sorting(f: String, order: String):
Expand Down

0 comments on commit bbe2f68

Please sign in to comment.