Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Going to the plaza for food. Also fix ES boost query support
Browse files Browse the repository at this point in the history
  • Loading branch information
Holden Karau committed Jun 17, 2012
1 parent 260d386 commit 2b5859b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/main/scala/com/foursquare/slashem/QueryBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
26 changes: 25 additions & 1 deletion src/test/scala/com/foursquare/slashem/ElasticQueryTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2b5859b

Please sign in to comment.