Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #46 from holdenk/master

Fix per-query boost with ES
  • Loading branch information...
commit 2399d2691931f9e672cf49d6c945273bbcc09570 2 parents a6dfebe + e59d252
@adamalix adamalix authored
View
2  build.sbt
@@ -1,6 +1,6 @@
name := "slashem"
-version := "0.13.1"
+version := "0.13.2"
organization := "com.foursquare"
View
10 src/main/scala/com/foursquare/slashem/Ast.scala
@@ -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)
}
}
}
View
16 src/main/scala/com/foursquare/slashem/Schema.scala
@@ -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
View
20 src/test/scala/com/foursquare/slashem/ElasticQueryTest.scala
@@ -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
@@ -159,6 +174,11 @@ class ElasticQueryTest extends SpecsMatchers with ScalaCheckMatchers {
Assert.assertEquals(1,r.response.results.length)
}
@Test
+ def testNonEmptyMultiFieldSearchWithFieldValues {
+ val r = ESimplePanda.where(_.default contains "onlyinnamefield").queryField(_.name,0.1).queryField(_.hobos,0.2) fetch()
+ Assert.assertEquals(1,r.response.results.length)
+ }
+ @Test
def testNonEmptySearchOidScorePare {
val r = ESimplePanda where (_.hobos contains "hobos") fetch()
Assert.assertEquals(1,r.response.results.length)
Please sign in to comment.
Something went wrong with that request. Please try again.