Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix query gen for ES Empty[T] queries.

TODO: We should optimize our tree before generating queries
  • Loading branch information...
commit 385e8e8d1d9f971d3b73aada3a36bbcb1bbe25b8 1 parent 6a048f4
@holdenk holdenk authored
View
6 src/main/scala/com/foursquare/slashem/Ast.scala
@@ -359,8 +359,10 @@ object Ast {
def extend(): String = "\"\""
/** @inheritdoc */
def elasticExtend(qf: List[WeightedField], pf: List[PhraseWeightedField], mm: Option[String]): ElasticQueryBuilder = {
- val q = EQueryBuilders.queryString(this.extend())
- qf.map(f => q.field(f.fieldName,f.weight.toFloat))
+ //An empty query matches no documents, so it is the same as the negation of matchAll
+ //Note: this is kind of ugly since this is may likely an OR clause or negated up above
+ //so we should try and avoid generating this
+ val q = EQueryBuilders.boolQuery.mustNot(EQueryBuilders.matchAllQuery())
q
}
}
View
14 src/test/scala/com/foursquare/slashem/ElasticQueryTest.scala
@@ -313,10 +313,20 @@ class ElasticQueryTest extends SpecsMatchers with ScalaCheckMatchers {
def testListFieldIn {
val response1 = ESimplePanda where (_.favnums in List(2, 3, 4, 5)) fetch()
val response2 = ESimplePanda where (_.favnums in List(99)) fetch()
- //val response3 = ESimplePanda where (_.favnums in List()) fetch()
Assert.assertEquals(response1.response.results.length, 2)
Assert.assertEquals(response2.response.results.length, 0)
- //Assert.assertEquals(response3.response.results.length, 0)
+ }
+
+ @Test
+ def testIntListFieldEmptyIn {
+ val response = ESimplePanda where (_.favnums in List()) fetch()
+ Assert.assertEquals(response.response.results.length, 0)
+ }
+
+ @Test
+ def testIntListFieldEmptyNin {
+ val response = ESimplePanda where (_.favnums nin List()) fetch()
+ Assert.assertEquals(response.response.results.length, 8)
}
@Test
Please sign in to comment.
Something went wrong with that request. Please try again.