Skip to content

Commit

Permalink
Optimizer, buttons, hulk smash. Also tests fail
Browse files Browse the repository at this point in the history
  • Loading branch information
Holden Karau committed May 15, 2012
1 parent 9f6355b commit 40aab3d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/main/scala/com/foursquare/slashem/Optimize.scala
Expand Up @@ -11,7 +11,9 @@ object Optimizer {
filters.filter(f => { filters.filter(f => {
f match { f match {
//Remove all empty search clauses //Remove all empty search clauses
case x: Query[Empty[_]] => false case x: Clause[Splat[_]] => {
false
}
case _ => true case _ => true
} }
}) })
Expand Down
6 changes: 5 additions & 1 deletion src/main/scala/com/foursquare/slashem/QueryBuilder.scala
Expand Up @@ -351,6 +351,10 @@ case class QueryBuilder[M <: Record[M], Ord, Lim, MM <: MinimumMatchType, Y, H <
() ()
} }


/* Optimize the QueryBuilder */
def optimize() = {
this.copy(filters=Optimizer.optimizeFilters(filters))
}


/** Fetch the results with the limit of l. Can only be used on an unlimited /** Fetch the results with the limit of l. Can only be used on an unlimited
* query */ * query */
Expand All @@ -366,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*/ /** Fetch the results for a given query (blocking) with a specified timeout*/
def fetch(timeout: Duration): SearchResults[M, Y] = { def fetch(timeout: Duration): SearchResults[M, Y] = {
// Gross++ // Gross++
meta.query(timeout, this) meta.query(timeout, this.optimize())
} }
/** Fetch the results for a given query (non-blocking)*/ /** Fetch the results for a given query (non-blocking)*/
def fetchFuture(): Future[SearchResults[M,Y]] = { def fetchFuture(): Future[SearchResults[M,Y]] = {
Expand Down
11 changes: 11 additions & 0 deletions src/test/scala/com/foursquare/slashem/QueryTest.scala
Expand Up @@ -98,6 +98,17 @@ class QueryTest extends SpecsMatchers with ScalaCheckMatchers {
"rows" -> "10").sortWith(_._1 > _._1)) "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 @Test
Expand Down

0 comments on commit 40aab3d

Please sign in to comment.