Skip to content

Commit

Permalink
Merge pull request #45 from holdenk/master
Browse files Browse the repository at this point in the history
Fix list field bugs
  • Loading branch information
adamalix committed Jun 28, 2012
2 parents 721bbae + 9b678af commit a6dfebe
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.sbt
@@ -1,6 +1,6 @@
name := "slashem" name := "slashem"


version := "0.13.0" version := "0.13.1"


organization := "com.foursquare" organization := "com.foursquare"


Expand Down
6 changes: 6 additions & 0 deletions src/main/scala/com/foursquare/slashem/Schema.scala
Expand Up @@ -1264,6 +1264,10 @@ class LongListField[T <: Record[T]](override val owner: T) extends Field[List[Lo
case "" => Empty case "" => Empty
case ar: Array[Long] => Full(set(ar.toList)) case ar: Array[Long] => Full(set(ar.toList))
case ar: Array[Integer] => Full(set(ar.toList.map(x => x.longValue))) case ar: Array[Integer] => Full(set(ar.toList.map(x => x.longValue)))
case ar: ArrayList[_] => Full(set(ar.toArray.asInstanceOf[Array[_]].toList.map(x =>{ x match {
case i: Integer => i.toLong
case l: Long => l
}})))
case s: String => Full(set(s.split(" ").map(x => x.toLong).toList)) case s: String => Full(set(s.split(" ").map(x => x.toLong).toList))
case _ => Empty case _ => Empty
} }
Expand Down Expand Up @@ -1301,6 +1305,7 @@ class ObjectIdListField[T <: Record[T]](override val owner: T) extends Field[Lis
case "" => Empty case "" => Empty
case ar: Array[ObjectId] => Full(ar.toList) case ar: Array[ObjectId] => Full(ar.toList)
case ar: Array[String] => Full(ar.toList.map(x => new ObjectId(x))) case ar: Array[String] => Full(ar.toList.map(x => new ObjectId(x)))
case ar: ArrayList[_] => Full(set(ar.toArray.toList.map(x => new ObjectId(x.asInstanceOf[String]))))
case s: String => Full(s.split(" ").map(x => new ObjectId(x)).toList) case s: String => Full(s.split(" ").map(x => new ObjectId(x)).toList)
case _ => Empty case _ => Empty
} }
Expand Down Expand Up @@ -1342,6 +1347,7 @@ class StringListField[T <: Record[T]](override val owner: T) extends Field[List[
case "" => Empty case "" => Empty
case arr: Array[String] => Full(arr.toList) case arr: Array[String] => Full(arr.toList)
case str: String => setFromString(str) case str: String => setFromString(str)
case ar: ArrayList[_] => Full(set(ar.toArray.toList.map(x => x.asInstanceOf[String])))
case _ => Empty case _ => Empty
} }
} catch { } catch {
Expand Down
17 changes: 16 additions & 1 deletion src/test/scala/com/foursquare/slashem/ElasticQueryTest.scala
Expand Up @@ -355,11 +355,26 @@ class ElasticQueryTest extends SpecsMatchers with ScalaCheckMatchers {


@Test @Test
def testIntListFieldReturn { def testIntListFieldReturn {
val response1 = ESimplePanda where (_.favnums contains 2) fetch() val response1 = ESimplePanda where (_.favnums contains 2) and (_.favnums contains 5) fetch()
Assert.assertEquals(response1.response.results.length, 2) Assert.assertEquals(response1.response.results.length, 2)
Assert.assertEquals(response1.response.results.head.favnums.get, List(1,2,3,4,5)) Assert.assertEquals(response1.response.results.head.favnums.get, List(1,2,3,4,5))
} }


@Test
def testLongListFieldReturn {
val response = ESimplePanda where (_.hugenums contains 9L) fetch()
Assert.assertEquals(response.response.results.length, 1)
Assert.assertEquals(response.response.results.head.hugenums.get, List(1L, 9L, 8L))
}

@Test
def testObjectIdListFieldReturn {
val response = ESimplePanda where (_.favvenueids contains new ObjectId("4daf213893a0096fbaaef003")) fetch()
val venueids1 = List("4daf213893a0096fbaaef003", "49ee02e9f964a52010681fe3", "42b21280f964a5206d251fe3")
Assert.assertEquals(response.response.results.length, 1)
Assert.assertEquals(response.response.results.head.favvenueids.get, venueids1)
}

@Test @Test
def testListFieldIn { def testListFieldIn {
val response1 = ESimplePanda where (_.favnums in List(2, 3, 4, 5)) fetch() val response1 = ESimplePanda where (_.favnums in List(2, 3, 4, 5)) fetch()
Expand Down

0 comments on commit a6dfebe

Please sign in to comment.