Mitch Pronschinske is the Lead Research Analyst at DZone. Researching and compiling content for DZone's research guides is his primary job. He likes to make his own ringtones, watches cartoons/anime, enjoys card and board games, and plays the accordion. Mitch is a DZone Zone Leader and has posted 2576 posts at DZone. You can read more from them at their website. View Full User Profile

Behold! A Solr Client for Scala

05.09.2012
| 5140 views |
  • submit to reddit
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