in src/main/scala/datastore/ElasticsearchRepo.scala [28:72]
override def docById(id: String): Future[Edge[Json]] = {
client.execute {
search("content")
.query(
BoolQuery(must=Seq(
MatchQuery("id", id),
MatchQuery("isGone", false),
MatchQuery("isExpired", false),
))
)
.sortByFieldDesc("webPublicationDate")
}.flatMap(response=>{
if(response.isSuccess) {
response
.result
.hits
.hits
.headOption
.map(h=>(h, io.circe.parser.parse(h.sourceAsString))) match {
case None=>
Future(
Edge(
0,
None,
false,
List[Json]()
)
)
case Some((_, Left(err)))=>
Future.failed(new RuntimeException(err))
case Some((hit, Right(json)))=>
Future(
Edge(
response.result.hits.total.value,
Edge.cursorValue(hit),
false,
List(json)
)
)
}
} else {
Future.failed(response.error.asException)
}
})
}