takezoe / solr-scala-client

Solr Client for Scala
Apache License 2.0
91 stars 43 forks source link

NPE when using groupBy #39

Closed dfrese closed 6 years ago

dfrese commented 6 years ago

Hi there,

in version 0.0.16, when using a .groupBy(..) clause on a query, getResultAsMap fails with a NullPointerException at com.github.takezoe.solr.scala.QueryBuilderBase.responseToMap(QueryBuilderBase.scala:229)

I don't have any experience with Solr, but maybe QueryResponse::getResults returns null, and the path through QueryResponse::getGroupResponse...getGroups...getResults etc. has to be taken in this case?

Or am I missing something?

Thanks for publishing the library though!

takezoe commented 6 years ago

@dfrese The current solr-scala-client can't handle the grouped result. I added grouped result support in 35aa457. You can get a grouped result as follows in the next version of solr-scala-client:

val result = client.query("*:*").groupBy("manu").getResultAsMap()
result.groups.foreach { case (name, groups) =>
  println("group name: " + name)
  groups.foreach { group =>
    println("  manu: " + group.value)
    println("  numFound: " + group.numFound)
    println("  docs: " + group.documents) // Map[String, Any]
  }
}

I will release the next version of solr-scala-client as soon as possible.

Thanks for your reporting!