Skip to content
This repository has been archived by the owner on Aug 8, 2020. It is now read-only.

Commit

Permalink
adding ngroups
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan S committed Oct 14, 2014
1 parent c7fe156 commit 1e526eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.apache.solr.common.util.{ NamedList, SimpleOrderedMap }
import org.apache.solr.common.SolrDocumentList

case class Groups(@BeanProperty val matches: Int = 0,
@BeanProperty val ngroups: Int = 0,
@BeanProperty val groups: List[Group]) {

def getGroupsInJava(): java.util.List[Group] = java.util.Arrays.asList(groups.toArray: _*)
Expand All @@ -47,6 +48,7 @@ object Groups {
writerType match {
case WriterType.Standard => {
var matches: Int = 0
var ngroups: Int = 0
val empty: List[Group] = Nil
val xml = XML.loadString(rawBody)
val groupedList = (xml \ "lst").filter(lst => (lst \ "@name").text == "grouped")
Expand All @@ -56,6 +58,7 @@ object Groups {
(groupedList.head \ "lst") flatMap {
case lst: Node =>
matches = (lst \ "int").filter(i => (i \ "@name").text == "matches").apply(0).text.toInt
ngroups = (lst \ "int").filter(i => (i \ "@name").text == "ngroups").apply(0).text.toInt
val arrList = (lst \ "arr").filter(lst => (lst \ "@name").text == "groups")
arrList.size match {
case 0 =>
Expand Down Expand Up @@ -96,6 +99,7 @@ object Groups {
}
new Groups(
matches = matches,
ngroups = ngroups,
groups = groups.toList
)
}
Expand All @@ -105,6 +109,7 @@ object Groups {
import collection.JavaConverters._

var matches: Int = 0
var ngroups: Int = 0
var groups: List[Group] = Nil

val grouped = rawJavaBin.get("grouped").asInstanceOf[SimpleOrderedMap[Any]]
Expand All @@ -116,6 +121,7 @@ object Groups {
val groupedValue = e.getValue.asInstanceOf[NamedList[Any]]
groupedValue.asScala foreach {
case e: MapEntry if e.getKey == "matches" => matches = e.getValue.toString.toInt
case e: MapEntry if e.getKey == "ngroups" => ngroups = e.getValue.toString.toInt
case e: MapEntry if e.getKey == "doclist" =>
// group.format=simple
val doclist = e.getValue.asInstanceOf[SolrDocumentList]
Expand Down Expand Up @@ -160,6 +166,7 @@ object Groups {
}
new Groups(
matches = matches,
ngroups = ngroups,
groups = groups
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ class GroupsSpec extends FlatSpec with ShouldMatchers {

it should "be available" in {
val matches: Int = 0
val ngroups: Int = 0
val groups: List[SolrGroup] = Nil
val instance = new Groups(matches, groups)
val instance = new Groups(matches, ngroups, groups)
instance should not be null
}

it should "have getDocumentsInJava" in {
val matches: Int = 0
val ngroups: Int = 0
val groups: List[SolrGroup] = List()
val gs = new Groups(matches, groups)
val gs = new Groups(matches, ngroups, groups)
gs.getGroupsInJava().size() should equal(0)
}

Expand Down

0 comments on commit 1e526eb

Please sign in to comment.