Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix optimizer.

* Optimizer now removes filter (_.metall any) . Yes this is kind of dumb but
  it is a good starting point.
  • Loading branch information...
commit 76f211c34fafe08b12915bdef68859fff803ac48 1 parent ece99e8
@holdenk holdenk authored
View
5 src/main/scala/com/foursquare/slashem/Optimize.scala
@@ -11,9 +11,8 @@ object Optimizer {
filters.filter(f => {
f match {
//Remove all empty search clauses
- case x: Clause[Splat[_]] => {
- false
- }
+ case Clause("*",Splat(),true) => false
+ case Clause("_all",Splat(),true) => false
case _ => true
}
})
View
2  src/main/scala/com/foursquare/slashem/QueryBuilder.scala
@@ -370,7 +370,7 @@ case class QueryBuilder[M <: Record[M], Ord, Lim, MM <: MinimumMatchType, Y, H <
/** Fetch the results for a given query (blocking) with a specified timeout*/
def fetch(timeout: Duration): SearchResults[M, Y] = {
// Gross++
- meta.query(timeout, this.optimize())
+ meta.query(timeout, this)
}
/** Fetch the results for a given query (non-blocking)*/
def fetchFuture(): Future[SearchResults[M,Y]] = {
View
5 src/test/scala/com/foursquare/slashem/ElasticQueryTest.scala
@@ -365,7 +365,7 @@ class ElasticQueryTest extends SpecsMatchers with ScalaCheckMatchers {
def testObjectIdListFieldEmptyNin {
val response1 = ESimplePanda where (_.favvenueids nin List()) fetch()
Assert.assertEquals(response1.response.results.length, 8)
- }
+ }
@Test
def testListFieldNin {
@@ -583,3 +583,6 @@ class ElasticQueryTest extends SpecsMatchers with ScalaCheckMatchers {
}
}
+
+object ElasticQueryTest extends ElasticQueryTest {
+}
View
74 src/test/scala/com/foursquare/slashem/OptimizeTest.scala
@@ -0,0 +1,74 @@
+package com.foursquare.slashem
+import com.foursquare.slashem._
+
+import com.twitter.util.Duration
+
+import org.bson.types.ObjectId
+import org.junit.Test
+import org.junit._
+
+import org.scalacheck._
+import org.scalacheck.Gen._
+import org.scalacheck.Arbitrary.arbitrary
+
+import org.specs.SpecsMatchers
+import org.specs.matcher.ScalaCheckMatchers
+
+import org.elasticsearch.node.NodeBuilder._
+import org.elasticsearch.node.Node
+import org.elasticsearch.client.Requests;
+import org.elasticsearch.common.xcontent.XContentFactory._;
+
+import java.util.concurrent.TimeUnit
+import java.util.UUID
+
+import scalaj.collection.Imports._
+
+import com.twitter.util.{Duration, ExecutorServiceFuturePool, Future, FuturePool, FutureTask, Throw, TimeoutException}
+import java.util.concurrent.{Executors, ExecutorService}
+
+class OptimizeTest extends SpecsMatchers with ScalaCheckMatchers {
+
+ //We test this because the optimizer screwed this up once
+ @Test
+ def testTermFiltersOptimize {
+ val q = ESimplePanda where (_.hugenums contains 1L) filter(_.termsfield in List("termhit", "randomterm"))
+ val res1 = q fetch()
+ val res2 = q optimize() fetch()
+ Assert.assertEquals(res1.response.results.length, res2.response.results.length)
+ }
+
+ @Test
+ def testTermFiltersMetallFilter {
+ val q = ESimpleGeoPanda where (_.name contains "ordertest") filter(_.metall any)
+ val q2 = ESimpleGeoPanda where (_.name contains "ordertest")
+ val res1 = q fetch()
+ val res2 = q optimize() fetch()
+ val res3 = q2 fetch()
+ Assert.assertEquals(res1.response.results.length, res2.response.results.length)
+ Assert.assertEquals(res1.response.results.length, res3.response.results.length)
+ Assert.assertEquals(q.optimize(),q2)
+ }
+
+ @Test
+ def testProduceCorrectListfieldFilterAny {
+ val q = SVenueTest where (_.metall any) filter (_.metall any)
+ val optimizedQ = q.optimize()
+ val qp = q.meta.queryParams(optimizedQ).toList
+ Assert.assertEquals(qp.sortWith(_._1 > _._1),
+ List("q" -> "*:*",
+ "start" -> "0",
+ "rows" -> "10").sortWith(_._1 > _._1))
+ }
+
+ @Before
+ def esSetup {
+ ElasticQueryTest.hoboPrepIndex()
+ }
+
+ @After
+ def esDone {
+ ElasticQueryTest.hoboDone()
+ }
+
+}
View
12 src/test/scala/com/foursquare/slashem/QueryTest.scala
@@ -98,18 +98,6 @@ class QueryTest extends SpecsMatchers with ScalaCheckMatchers {
"rows" -> "10").sortWith(_._1 > _._1))
}
- @Test
- def testProduceCorrectListfieldFilterAny {
- val q = SVenueTest where (_.metall any) filter (_.metall any)
- val optimizedQ = q.optimize()
- val qp = q.meta.queryParams(optimizedQ).toList
- Assert.assertEquals(qp.sortWith(_._1 > _._1),
- List("q" -> "*:*",
- "start" -> "0",
- "rows" -> "10").sortWith(_._1 > _._1))
- }
-
-
@Test
def testProduceCorrectSimpleQueryStringContains {

0 comments on commit 76f211c

Please sign in to comment.
Something went wrong with that request. Please try again.