Over a million developers have joined DZone.

Behold! A Solr Client for Scala

· Java Zone

Discover how powerful static code analysis and ergonomic design make development not only productive but also an enjoyable experience, brought to you in partnership with JetBrains

Scala users, check this out!  If you've been trying to have a better interface for using Apache Solr in your Scala projects, there's a pretty new simple Solr client for Scala being developed on GitHub by Naoki Takezoe.  It hasn't been released yet but if this project is of interest to you, it might be worth it to lend a hand.

The client is based on SolrJ and you simply add a dependency into your build.sbt.  Here is the simplest example of its usage:
import jp.sf.amateras.solr.scala._

val client = new SolrClient("http://localhost:8983/solr")

// register
client
  .add(Map("id"->"001", "manu" -> "Lenovo", "name" -> "ThinkPad X201s"))
  .add(Map("id"->"002", "manu" -> "Lenovo", "name" -> "ThinkPad X220"))
  .add(Map("id"->"003", "manu" -> "Lenovo", "name" -> "ThinkPad X121e"))
  .commit

// query
val result: List[Map[String, Any]] =
  client.query("name:%name%")
    .fields("id", "manu", "name")
    .sortBy("id", Order.asc)
    .getResult(Map("name" -> "ThinkPad"))

result.foreach { doc: Map[String, Any] =>
  println("id: " + doc("id"))
  println("  manu: " + doc("manu"))
  println("  name: " + doc("name"))
}
Here is the list of features that Takezoe wants to add before release:

  •     Mapping document to case class
  •     Flexible configuration to SolrServer
  •     Facet search

Learn more about Kotlin, a new programming language designed to solve problems that software developers face every day brought to you in partnership with JetBrains.

Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}