Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Sample of using Scala with the Java DSL of Lagom
package com.lightbend.conductr.eslite
import javax.inject.Named
import akka.NotUsed
import akka.pattern.ask
import com.fasterxml.jackson.databind.node.ObjectNode
import com.lightbend.conductr.eslite.dto._
import com.lightbend.lagom.javadsl.api.ServiceCall
import scala.collection.JavaConverters._
import scala.compat.java8.FutureConverters._
import scala.compat.java8.OptionConverters._
import scala.concurrent.Future
import com.lightbend.conductr.eslite.QueryParser._
import akka.util.Timeout
import scala.concurrent.duration._
class EsliteServiceImpl @Inject() (@Named("BundleIdSourceCache") bundleIdSourceCache: ActorRef) extends EsliteService {
implicit val timeout = akka.util.Timeout(2.seconds)
override def bulkIndex(): ServiceCall[NotUsed, BulkRequest, BulkReply] = { (id, request) =>
bundleIdSourceCache ! BundleIdSourceCache.Append( => {
val item = BulkLineItem.builder().source(bli).build()
item.getBundleId -> item.getSource
override def search(): ServiceCall[SearchQuery, NotUsed, SearchReply] = { (id, request) =>
val parsed = ParsedSearchQuery(id)
QueryProcessor.process(parsed, bundleIdSourceCache).map { results =>
val hits = { o =>
SearchReply.builder().hits(Hits.builder().addHits(hits.toArray: _*).build()).build
case class ParsedSearchQuery(expr: Expr, size: Int, sort: String)
object ParsedSearchQuery {
def apply(query: SearchQuery): ParsedSearchQuery = {
val expr = QueryParser.parse(query.getQ)
ParsedSearchQuery(expr, query.getSize, query.getSort)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.