Skip to content
Browse files

Optimizer, buttons, hulk smash. Also tests fail

  • Loading branch information...
1 parent 9f6355b commit 40aab3dc089d9abe1953d66c0243d10c59c40c66 @holdenk committed May 15, 2012
View
4 src/main/scala/com/foursquare/slashem/Optimize.scala
@@ -11,7 +11,9 @@ object Optimizer {
filters.filter(f => {
f match {
//Remove all empty search clauses
- case x: Query[Empty[_]] => false
+ case x: Clause[Splat[_]] => {
+ false
+ }
case _ => true
}
})
View
6 src/main/scala/com/foursquare/slashem/QueryBuilder.scala
@@ -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
* query */
@@ -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*/
def fetch(timeout: Duration): SearchResults[M, Y] = {
// Gross++
- meta.query(timeout, this)
+ meta.query(timeout, this.optimize())
}
/** Fetch the results for a given query (non-blocking)*/
def fetchFuture(): Future[SearchResults[M,Y]] = {
View
11 src/test/scala/com/foursquare/slashem/QueryTest.scala
@@ -98,6 +98,17 @@ 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

0 comments on commit 40aab3d

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