Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add boosting for eqs/neqs query and fix Solr boost query gen for nega…

…tive queries
  • Loading branch information...
commit fa6d1624ab28ed3ab8d6d5b0f6094590afcc72f3 1 parent 54d692b
@holdenk holdenk authored
View
17 src/main/scala/com/foursquare/slashem/Ast.scala
@@ -159,23 +159,30 @@ object Ast {
case class Clause[T](fieldName: String, query: Query[T], plus: Boolean = true) extends AbstractClause {
/** @inheritdoc */
def extend(): String = {
- val q = query match {
- case Group(x) => query
- case Splat() => query
- case _ => Group(query)
+ val (q,boost) = query match {
+ case Group(x) => (query,1)
+ case Splat() => (query,1)
+ case Boost(Group(x),b) => (Group(x),b)
+ case Boost(x,b) => (Group(x),b)
+ case _ => (Group(query),1)
}
// If a field does not have a name then do not attempt to specify it
val qstr = fieldName match {
case "" => q.extend()
case x => x + ":" + q.extend()
}
- plus match {
+ val booleanQuery = plus match {
case true => qstr
//This is added as a work around for the lack of support of
//pure negative queries (even though its partially supported
//now it turns out they don't work so well when nested)
case false => "(*:* -"+qstr+")"
}
+ //Boost as approraite
+ boost match {
+ case 1.0 => booleanQuery
+ case x => booleanQuery+"^"+x
+ }
}
/** @inheritdoc */
View
6 src/main/scala/com/foursquare/slashem/Schema.scala
@@ -730,9 +730,13 @@ trait SlashemField[V, M <: Record[M]] extends OwnedField[M] {
self: Field[V, M] =>
import Helpers._
- //Not eqs and neqs results in phrase queries!
+ //Note eqs and neqs results in phrase queries!
def eqs(v: V) = Clause[V](self.queryName, Group(Phrase(v)))
def neqs(v: V) = Clause[V](self.queryName, Phrase(v),false)
+ //With a boost
+ def eqs(v: V, b: Float) = Clause[V](self.queryName, Boost(Group(Phrase(v)),b))
+ def neqs(v: V, b:Float) = Clause[V](self.queryName, Boost(Phrase(v),b),false)
+
//This allows for bag of words style matching.
def contains(v: V) = Clause[V](self.queryName, Group(BagOfWords(v)))
View
22 src/test/scala/com/foursquare/slashem/QueryTest.scala
@@ -98,6 +98,18 @@ class QueryTest extends SpecsMatchers with ScalaCheckMatchers {
}
@Test
+ def testProduceCorrectSimpleQueryStringWithBoostNeq {
+ val q = SUserTest where (_.fullname eqs "jon") useQueryType("edismax") boostQuery(_.fullname neqs("fnur",123))
+ val qp = q.meta.queryParams(q).toList
+ Assert.assertEquals(qp.sortWith(_._1 > _._1),List("q" -> """fullname:("jon")""",
+ "start" -> "0",
+ "defType" -> "edismax",
+ "bq" -> """(*:* -fullname:("fnur"))^123.0""",
+ "rows" -> "10").sortWith(_._1 > _._1))
+ }
+
+
+ @Test
def testProduceCorrectEdisMaxQueryString {
val q = SUserTest where (_.fullname eqs "holden") useQueryType("edismax")
val qp = q.meta.queryParams(q).toList
@@ -437,7 +449,7 @@ class QueryTest extends SpecsMatchers with ScalaCheckMatchers {
"qf" -> "ngram_name^0.2",
"qf" -> "tags^0.01",
"tieBreaker" -> "0.2",
- "bq" -> "name:((holden's hobohut)^10.0)",
+ "bq" -> "name:(holden's hobohut)^10.0",
"bf" -> "recip(sqedist(%s,%s,lat,lng), 1, 5000, 1)".format(geoLat,geoLong),
"bf" -> "decayedPopularity1",
"rows" -> "10")
@@ -469,7 +481,7 @@ class QueryTest extends SpecsMatchers with ScalaCheckMatchers {
"qf" -> "tags^0.01",
"tieBreaker" -> "0.2",
"fl" -> "id,name,userid,mayorid,category_id_0,popularity,decayedPopularity1,lat,lng,checkin_info,score,hasSpecial,address,crossstreet,city,state,zip,country,checkinCount",
- "bq" -> "name:((holden's hobohut)^10.0)",
+ "bq" -> "name:(holden's hobohut)^10.0",
"bf" -> "recip(sqedist(%s,%s,lat,lng), 1, 5000, 1)".format(geoLat,geoLong),
"bf" -> "decayedPopularity1",
"rows" -> "10")
@@ -500,7 +512,7 @@ class QueryTest extends SpecsMatchers with ScalaCheckMatchers {
"qf" -> "tags^0.01",
"tieBreaker" -> "0.2",
"fl" -> "id,name,userid,mayorid,category_id_0,popularity,decayedPopularity1,lat,lng,checkin_info,score,hasSpecial,address,crossstreet,city,state,zip,country,checkinCount,partitionedPopularity",
- "bq" -> "name:((holden's hobohut)^10.0)",
+ "bq" -> "name:(holden's hobohut)^10.0",
"bf" -> "recip(sqedist(%s,%s,lat,lng), 1, 5000, 1)".format(geoLat,geoLong),
"bf" -> "decayedPopularity1",
"rows" -> "10")
@@ -532,7 +544,7 @@ class QueryTest extends SpecsMatchers with ScalaCheckMatchers {
"fq" -> "geo_s2_cell_ids:(\"pleaseUseaRealGeoHash\")",
"tieBreaker" -> "0.2",
"fl" -> "id,name,userid,mayorid,category_id_0,popularity,decayedPopularity1,lat,lng,checkin_info,score,hasSpecial,address,crossstreet,city,state,zip,country,checkinCount,partitionedPopularity",
- "bq" -> "name:((holden's hobohut)^10.0)",
+ "bq" -> "name:(holden's hobohut)^10.0",
"bf" -> "recip(sqedist(%s,%s,lat,lng), 1, 5000, 1)".format(geoLat,geoLong),
"bf" -> "decayedPopularity1",
"rows" -> "10")
@@ -579,7 +591,7 @@ class QueryTest extends SpecsMatchers with ScalaCheckMatchers {
"fq" -> "geo_s2_cell_ids:(\"pleaseUseaRealGeoHash\")",
"tieBreaker" -> "0.2",
"fl" -> "id,name,userid,mayorid,category_id_0,popularity,decayedPopularity1,lat,lng,checkin_info,score,hasSpecial,address,crossstreet,city,state,zip,country,checkinCount,partitionedPopularity",
- "bq" -> "name:((holden's hobohut)^10.0)",
+ "bq" -> "name:(holden's hobohut)^10.0",
"bf" -> "recip(sqedist(%s,%s,lat,lng),1,5000,1)".format(geoLat,geoLong),
"bf" -> "decayedPopularity1",
"rows" -> "10")
Please sign in to comment.
Something went wrong with that request. Please try again.