Mitch Pronschinske is a Senior Content Analyst at DZone. That means he writes and searches for the finest developer content in the land so that you don't have to. He often eats peanut butter and bananas, likes to make his own ringtones, enjoys card and board games, and is married to an underwear model. Mitch is a DZone Zone Leader and has posted 2573 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
| 4945 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