forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnv.scala
49 lines (37 loc) · 1.28 KB
/
Env.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package lila.teamSearch
import akka.actor._
import com.typesafe.config.Config
import lila.db.dsl._
import lila.search._
final class Env(
config: Config,
makeClient: Index => ESClient,
system: ActorSystem) {
private val IndexName = config getString "index"
private val PaginatorMaxPerPage = config getInt "paginator.max_per_page"
private val ActorName = config getString "actor.name"
private val client = makeClient(Index(IndexName))
val api = new TeamSearchApi(client)
def apply(text: String, page: Int) = paginatorBuilder(Query(text), page)
def cli = new lila.common.Cli {
def process = {
case "team" :: "search" :: "reset" :: Nil => api.reset inject "done"
}
}
private lazy val paginatorBuilder = new lila.search.PaginatorBuilder[lila.team.Team, Query](
searchApi = api,
maxPerPage = PaginatorMaxPerPage)
system.actorOf(Props(new Actor {
import lila.team.actorApi._
def receive = {
case InsertTeam(team) => api store team
case RemoveTeam(id) => client deleteById Id(id)
}
}), name = ActorName)
}
object Env {
lazy val current = "teamSearch" boot new Env(
config = lila.common.PlayApp loadConfig "teamSearch",
makeClient = lila.search.Env.current.makeClient,
system = lila.common.PlayApp.system)
}