Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Holden Karau holdenk authored
5 src/main/scala/com/foursquare/slashem/Optimize.scala
@@ -11,9 +11,8 @@ object Optimizer {
11 11 filters.filter(f => {
12 12 f match {
13 13 //Remove all empty search clauses
14   - case x: Clause[Splat[_]] => {
15   - false
16   - }
  14 + case Clause("*",Splat(),true) => false
  15 + case Clause("_all",Splat(),true) => false
17 16 case _ => true
18 17 }
19 18 })
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 <
370 370 /** Fetch the results for a given query (blocking) with a specified timeout*/
371 371 def fetch(timeout: Duration): SearchResults[M, Y] = {
372 372 // Gross++
373   - meta.query(timeout, this.optimize())
  373 + meta.query(timeout, this)
374 374 }
375 375 /** Fetch the results for a given query (non-blocking)*/
376 376 def fetchFuture(): Future[SearchResults[M,Y]] = {
5 src/test/scala/com/foursquare/slashem/ElasticQueryTest.scala
@@ -365,7 +365,7 @@ class ElasticQueryTest extends SpecsMatchers with ScalaCheckMatchers {
365 365 def testObjectIdListFieldEmptyNin {
366 366 val response1 = ESimplePanda where (_.favvenueids nin List()) fetch()
367 367 Assert.assertEquals(response1.response.results.length, 8)
368   - }
  368 + }
369 369
370 370 @Test
371 371 def testListFieldNin {
@@ -583,3 +583,6 @@ class ElasticQueryTest extends SpecsMatchers with ScalaCheckMatchers {
583 583 }
584 584
585 585 }
  586 +
  587 +object ElasticQueryTest extends ElasticQueryTest {
  588 +}
74 src/test/scala/com/foursquare/slashem/OptimizeTest.scala
... ... @@ -0,0 +1,74 @@
  1 +package com.foursquare.slashem
  2 +import com.foursquare.slashem._
  3 +
  4 +import com.twitter.util.Duration
  5 +
  6 +import org.bson.types.ObjectId
  7 +import org.junit.Test
  8 +import org.junit._
  9 +
  10 +import org.scalacheck._
  11 +import org.scalacheck.Gen._
  12 +import org.scalacheck.Arbitrary.arbitrary
  13 +
  14 +import org.specs.SpecsMatchers
  15 +import org.specs.matcher.ScalaCheckMatchers
  16 +
  17 +import org.elasticsearch.node.NodeBuilder._
  18 +import org.elasticsearch.node.Node
  19 +import org.elasticsearch.client.Requests;
  20 +import org.elasticsearch.common.xcontent.XContentFactory._;
  21 +
  22 +import java.util.concurrent.TimeUnit
  23 +import java.util.UUID
  24 +
  25 +import scalaj.collection.Imports._
  26 +
  27 +import com.twitter.util.{Duration, ExecutorServiceFuturePool, Future, FuturePool, FutureTask, Throw, TimeoutException}
  28 +import java.util.concurrent.{Executors, ExecutorService}
  29 +
  30 +class OptimizeTest extends SpecsMatchers with ScalaCheckMatchers {
  31 +
  32 + //We test this because the optimizer screwed this up once
  33 + @Test
  34 + def testTermFiltersOptimize {
  35 + val q = ESimplePanda where (_.hugenums contains 1L) filter(_.termsfield in List("termhit", "randomterm"))
  36 + val res1 = q fetch()
  37 + val res2 = q optimize() fetch()
  38 + Assert.assertEquals(res1.response.results.length, res2.response.results.length)
  39 + }
  40 +
  41 + @Test
  42 + def testTermFiltersMetallFilter {
  43 + val q = ESimpleGeoPanda where (_.name contains "ordertest") filter(_.metall any)
  44 + val q2 = ESimpleGeoPanda where (_.name contains "ordertest")
  45 + val res1 = q fetch()
  46 + val res2 = q optimize() fetch()
  47 + val res3 = q2 fetch()
  48 + Assert.assertEquals(res1.response.results.length, res2.response.results.length)
  49 + Assert.assertEquals(res1.response.results.length, res3.response.results.length)
  50 + Assert.assertEquals(q.optimize(),q2)
  51 + }
  52 +
  53 + @Test
  54 + def testProduceCorrectListfieldFilterAny {
  55 + val q = SVenueTest where (_.metall any) filter (_.metall any)
  56 + val optimizedQ = q.optimize()
  57 + val qp = q.meta.queryParams(optimizedQ).toList
  58 + Assert.assertEquals(qp.sortWith(_._1 > _._1),
  59 + List("q" -> "*:*",
  60 + "start" -> "0",
  61 + "rows" -> "10").sortWith(_._1 > _._1))
  62 + }
  63 +
  64 + @Before
  65 + def esSetup {
  66 + ElasticQueryTest.hoboPrepIndex()
  67 + }
  68 +
  69 + @After
  70 + def esDone {
  71 + ElasticQueryTest.hoboDone()
  72 + }
  73 +
  74 +}
12 src/test/scala/com/foursquare/slashem/QueryTest.scala
@@ -98,18 +98,6 @@ class QueryTest extends SpecsMatchers with ScalaCheckMatchers {
98 98 "rows" -> "10").sortWith(_._1 > _._1))
99 99 }
100 100
101   - @Test
102   - def testProduceCorrectListfieldFilterAny {
103   - val q = SVenueTest where (_.metall any) filter (_.metall any)
104   - val optimizedQ = q.optimize()
105   - val qp = q.meta.queryParams(optimizedQ).toList
106   - Assert.assertEquals(qp.sortWith(_._1 > _._1),
107   - List("q" -> "*:*",
108   - "start" -> "0",
109   - "rows" -> "10").sortWith(_._1 > _._1))
110   - }
111   -
112   -
113 101
114 102 @Test
115 103 def testProduceCorrectSimpleQueryStringContains {

0 comments on commit 76f211c

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