solr-scala-client 0.0.2 is now available!

solr-scala-client is a Apache Solr client for Scala wrapping SolrJ.

The list of new features in 0.0.2:

  • Added initializer which configures SolrClient.
  • Added basic authentication support as initializer.
  • Added facet search support.
  • Added case class support as query results and query parameters.

The query result became to be returned as MapQueryResult or CaseClassQueryResult instead of List[Map[String, Any]]. This object contains both of documents and facet counts.

val result = client.query("name:%name%")
      .fields("id", "manu", "name")
      .sortBy("id", Order.asc)
      .getResultAsMap(Map("name" -> "ThinkPad X201s"))

// retreive documents
result.documents.foreach { doc =>
  println("id: " + doc("id"))
  println("  manu: " + doc("manu"))
  println("  name: " + doc("name"))

// retreive facet counts
result.facetFields.foreach { case (field, counts) =>
  println("field: " + field)
  counts.foreach { case (manu, count) =>
    println("  " + manu + ": " + count)

It's possible to use the case class as the query result and the query parameter instead of Map[String, Any]. Note: update operations don't support the case class in 0.0.2. It will be supported in the next version.

// the case class for the document
case class Product(id: String, manu: Option[String], name: String)
// the case class for the parameter
case class Param(name: String)

// query using case classes
val result = client.query("name:%name%")
      .fields("id", "manu", "name")
      .sortBy("id", Order.asc)

result.documents.foreach { product =>

As small improvement of SolrClient, it became to accept the initializer function. This function takes CommonsHttpSolrServer and can do any processing for it.

val client = new SolrClient("http://localhost:8983/solr", {
  server: CommonsHttpSolrServer => // initialize...

0.0.2 contains the BASIC authentication support as the initializer. see the following example.

val client = new SolrClient("http://localhost:8983/solr", 
  Auth.basic("username", "password"))

I think solr-scala-client does not have enough features to use in production yet. Therefore I will improve it through use in my project.

0 件のコメント: