Permalink
Browse files

Fix per-query boost with ES

  • Loading branch information...
1 parent 9b678af commit 0d50b976b71e45e935f58dfbcaaaeffb852370be Holden Karau committed Jul 10, 2012
View
@@ -1,6 +1,6 @@
name := "slashem"
-version := "0.13.1"
+version := "0.13.2"
organization := "com.foursquare"
@@ -612,14 +612,8 @@ object Ast {
def extend(): String = q.extend() + "^" + weight.toString
/** @inheritdoc */
def elasticExtend(qf: List[WeightedField], pf: List[PhraseWeightedField], mm: Option[String]): ElasticQueryBuilder = {
- val boostedQuery = EQueryBuilders.boostingQuery
- if (weight > 0) {
- boostedQuery.positive(q.elasticExtend(qf, pf, mm))
- } else {
- boostedQuery.negative(q.elasticExtend(qf, pf, mm))
- }
- boostedQuery.boost(weight.abs)
- boostedQuery
+ val boostedQuery = EQueryBuilders.customBoostFactorQuery(q.elasticExtend(qf, pf, mm))
+ boostedQuery.boostFactor(weight)
}
}
}
@@ -681,12 +681,16 @@ trait ElasticSchema[M <: Record[M]] extends SlashemSchema[M] {
boostedQuery.positive(query)
boostedQuery.negative(query)
boostQueries.map(q => q match {
- case Clause(_,_,false) => boostedQuery.negative(q.elasticExtend(qb.queryFields,
- qb.phraseBoostFields,
- qb.minimumMatch))
- case _ => boostedQuery.positive(q.elasticExtend(qb.queryFields,
- qb.phraseBoostFields,
- qb.minimumMatch))
+ case Clause(_,_,false) => {
+ boostedQuery.negative(q.elasticExtend(qb.queryFields,
+ qb.phraseBoostFields,
+ qb.minimumMatch))
+ }
+ case _ => {
+ boostedQuery.positive(q.elasticExtend(qb.queryFields,
+ qb.phraseBoostFields,
+ qb.minimumMatch))
+ }
})
boostedQuery.negativeBoost(0.1.toFloat)
boostedQuery
@@ -94,15 +94,30 @@ class ElasticQueryTest extends SpecsMatchers with ScalaCheckMatchers {
}
@Test
+ def testQueryWithContains10 {
+ val rLoler10 = ESimplePanda where (_.name contains("loler",10)) fetch()
+ Assert.assertEquals(4,rLoler10.response.results.length)
+ }
+
+ @Test
+ def testBoostQueryWithPositive {
+ val rBoostedNyet10 = ESimplePanda where (_.name contains "loler") boostQuery(_.hobos contains("nyet",10)) fetch()
+ Assert.assertEquals(4,rBoostedNyet10.response.results.length)
+ }
+
+ @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()
+ val rBoostedNyet10 = ESimplePanda where (_.name contains "loler") boostQuery(_.hobos contains("nyet",10)) fetch()
Assert.assertEquals(1,rLolerNyet.response.results.length)
Assert.assertEquals(4,rBoostedNyet.response.results.length)
+ Assert.assertEquals(4,rBoostedNyet10.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)
+ Assert.assertTrue(rBoostedNyet10.response.results.apply(0).id.is != rNoBoostedNyet.response.results.apply(0).id.is)
}
@Test

0 comments on commit 0d50b97

Please sign in to comment.