-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94a59e0
commit 77a7dfd
Showing
10 changed files
with
95 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<configuration> | ||
|
||
<appender name="FILE" class="ch.qos.logback.core.FileAppender"> | ||
<file>logs/application.log</file> | ||
<encoder> | ||
<pattern>%date [%thread] %-5level %logger{20} - %msg%n%xException</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%date [%thread] %-5level %logger{20} - %msg%n%xException</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="INFO"> | ||
<appender-ref ref="STDOUT"/> | ||
<appender-ref ref="FILE"/> | ||
</root> | ||
|
||
<logger name="http4s"/> | ||
</configuration> |
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,21 @@ | ||
package lila.search | ||
package app | ||
|
||
import cats.effect.* | ||
import org.typelevel.log4cats.Logger | ||
import com.sksamuel.elastic4s.http.JavaClient | ||
import com.sksamuel.elastic4s.cats.effect.instances.* | ||
import com.sksamuel.elastic4s.{ ElasticClient, ElasticProperties } | ||
|
||
class AppResources private (val esClient: ESClient[IO]) | ||
|
||
object AppResources: | ||
|
||
def instance(conf: AppConfig)(using Logger[IO]): Resource[IO, AppResources] = | ||
makeClient(conf.elastic) | ||
.map(ESClient.apply[IO]) | ||
.map(AppResources(_)) | ||
|
||
def makeClient(conf: ElasticConfig): Resource[IO, ElasticClient] = | ||
Resource.make(IO(ElasticClient(JavaClient(ElasticProperties(conf.uri))))): client => | ||
IO(client.close()) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package lila.search | ||
package app | ||
|
||
import cats.effect.* | ||
import lila.search.spec.* | ||
import org.typelevel.log4cats.Logger | ||
import org.typelevel.log4cats.syntax.* | ||
import forum.ForumQuery.* | ||
import io.github.arainko.ducktape.* | ||
|
||
class SearchServiceImpl(esClient: ESClient[IO])(using Logger[IO]) extends SearchService[IO]: | ||
|
||
override def countForum(text: String, troll: Boolean): IO[CountResponse] = | ||
esClient | ||
.count(Index("forum"), Forum(text, troll)) | ||
.map(_.to[CountResponse]) | ||
.handleErrorWith: e => | ||
error"Error in countForum: text=$text, troll=$troll" *> | ||
IO.raiseError(InternalServerError("Internal server error")) | ||
|
||
override def searchForum(body: ForumInputBody, from: Int, size: Int): IO[SearchResponse] = | ||
esClient | ||
.search(Index("forum"), Forum(body.text, body.troll), From(from), Size(size)) | ||
.map(_.to[SearchResponse]) | ||
.handleErrorWith: e => | ||
error"Error in searchForum: body=$body, from=$from, size=$size" *> | ||
IO.raiseError(InternalServerError("Internal server error")) |
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
File renamed without changes.