order search ranges

pull/83/head
Thibault Duplessis 2012-09-08 12:12:21 +02:00
parent 1a0fcd144b
commit ef46d939d6
2 changed files with 13 additions and 4 deletions

View File

@ -2,8 +2,9 @@ package lila
package search
import org.elasticsearch.index.query._, FilterBuilders._
import org.joda.time.DateTime
case class Range[A](a: Option[A], b: Option[A]) {
final class Range[A] private (val a: Option[A], val b: Option[A]) {
def filters(name: String) = a.fold(
aa b.fold(
@ -13,12 +14,20 @@ case class Range[A](a: Option[A], b: Option[A]) {
b.toList map { bb rangeFilter(name) lte bb }
)
def map[B](f: A B) = Range(a map f, b map f)
def map[B](f: A B) = new Range(a map f, b map f)
def nonEmpty = a.nonEmpty || b.nonEmpty
}
object Range {
def none[A]: Range[A] = Range(None, None)
def apply[A](a: Option[A], b: Option[A])(implicit o: Ordering[A]): Range[A] =
(a, b) match {
case (Some(aa), Some(bb)) o.lt(aa, bb).fold(
new Range(a, b), new Range(b, a)
)
case (x, y) new Range(x, y)
}
def none[A]: Range[A] = new Range(None, None)
}

View File

@ -18,7 +18,7 @@ trait Dependencies {
val scalaz = "org.scalaz" %% "scalaz-core" % "6.0.4"
val specs2 = "org.specs2" %% "specs2" % "1.12"
val salat = "com.novus" %% "salat-core" % "1.9.1"
val scalalib = "com.github.ornicar" %% "scalalib" % "2.1"
val scalalib = "com.github.ornicar" %% "scalalib" % "2.2"
val config = "com.typesafe" % "config" % "0.4.1"
val guava = "com.google.guava" % "guava" % "13.0"
val apache = "org.apache.commons" % "commons-lang3" % "3.1"