Skip to content
Browse files

Going to the plaza for food. Also fix ES boost query support

  • Loading branch information...
1 parent 260d386 commit 2b5859b66230488d6cd381b44015ee90cda4a920 @holdenk holdenk committed
View
3 src/main/scala/com/foursquare/slashem/QueryBuilder.scala
@@ -111,7 +111,8 @@ case class QueryBuilder[M <: Record[M], Ord, Lim, MM <: MinimumMatchType, Y, H <
@param f The boost query
*/
def boostQuery[F](f: M => Clause[F]): QueryBuilder[M, Ord, Lim, MM, Y, H, Q, MinFacetCount, FacetLimit, ST] = {
- this.copy(boostQueries=f(meta) :: boostQueries)
+ val newclause = f(meta)
+ this.copy(boostQueries=newclause :: boostQueries)
}
/** Helper method for case class extraction */
View
26 src/test/scala/com/foursquare/slashem/ElasticQueryTest.scala
@@ -93,6 +93,30 @@ class ElasticQueryTest extends SpecsMatchers with ScalaCheckMatchers {
val r = fullQuery fetch()
}
+ @Test
+ def testBoostQuery {
+ val rLolerNyet = ESimplePanda where (_.name contains "loler") and (_.hobos contains "nyet") fetch()
+ val rBoostedNyet = ESimplePanda where (_.name contains "loler") boostQuery(_.hobos contains "nyet") fetch()
+ val rNoBoostedNyet = ESimplePanda where (_.name contains "loler") fetch()
+ Assert.assertEquals(1,rLolerNyet.response.results.length)
+ Assert.assertEquals(4,rBoostedNyet.response.results.length)
+ Assert.assertEquals(4,rNoBoostedNyet.response.results.length)
+ Assert.assertEquals(rBoostedNyet.response.results.apply(0).id.is,rLolerNyet.response.results.apply(0).id.is)
+ Assert.assertTrue(rBoostedNyet.response.results.apply(0).id.is != rNoBoostedNyet.response.results.apply(0).id.is)
+ }
+
+ @Test
+ def testNegativeBoostQuery {
+ val rLolerNyet = ESimplePanda where (_.name contains "loler") and (_.hobos.neqs("nyet")) fetch()
+ val rBoostedNyet = ESimplePanda where (_.name contains "loler") boostQuery(_.hobos.neqs("nyet")) fetch()
+ val rNoBoostedNyet = ESimplePanda where (_.name contains "loler") fetch()
+ Assert.assertEquals(3,rLolerNyet.response.results.length)
+ Assert.assertEquals(4,rBoostedNyet.response.results.length)
+ Assert.assertEquals(4,rNoBoostedNyet.response.results.length)
+ Assert.assertTrue(rBoostedNyet.response.results.apply(0).id.is != rNoBoostedNyet.response.results.apply(0).id.is)
+ }
+
+
@Test
def testEmptySearch {
@@ -247,7 +271,7 @@ class ElasticQueryTest extends SpecsMatchers with ScalaCheckMatchers {
val containsCount = rContains.response.results.length
Assert.assertTrue(containsCount > phraseCount)
}
- //@Test
+ @Test
def testFieldFaceting {
val r = ESimplePanda where (_.name contains "loler skates") facetField(_.foreign) fetch()
Assert.assertEquals(4,r.response.results.length)

0 comments on commit 2b5859b

Please sign in to comment.
Something went wrong with that request. Please try again.