Remove deprecated search routes and some refactoring

This commit is contained in:
Eike Kettner
2021-03-27 22:03:43 +01:00
parent bd5dba9f8e
commit cc38b850a6
16 changed files with 167 additions and 507 deletions

View File

@ -119,6 +119,8 @@ object ItemQuery {
final case class ChecksumMatch(checksum: String) extends Expr
final case class AttachId(id: String) extends Expr
case object ValidItemStates extends Expr
// things that can be expressed with terms above
sealed trait MacroExpr extends Expr {
def body: Expr

View File

@ -0,0 +1,76 @@
package docspell.query
import cats.data.NonEmptyList
import docspell.query.ItemQuery._
import docspell.query.internal.ExprUtil
object ItemQueryDsl {
implicit final class StringAttrDsl(val attr: Attr.StringAttr) extends AnyVal {
def ===(value: String): Expr =
Expr.SimpleExpr(Operator.Eq, Property(attr, value))
def <=(value: String): Expr =
Expr.SimpleExpr(Operator.Lte, Property(attr, value))
def >=(value: String): Expr =
Expr.SimpleExpr(Operator.Gte, Property(attr, value))
def <(value: String): Expr =
Expr.SimpleExpr(Operator.Lt, Property(attr, value))
def >(value: String): Expr =
Expr.SimpleExpr(Operator.Gt, Property(attr, value))
def in(values: NonEmptyList[String]): Expr =
Expr.InExpr(attr, values)
def exists: Expr =
Expr.Exists(attr)
def notExists: Expr =
Expr.NotExpr(exists)
}
implicit final class DateAttrDsl(val attr: Attr.DateAttr) extends AnyVal {
def <=(value: Date): Expr =
Expr.SimpleExpr(Operator.Lte, Property(attr, value))
def >=(value: Date): Expr =
Expr.SimpleExpr(Operator.Gte, Property(attr, value))
}
implicit final class ExprDsl(val expr: Expr) extends AnyVal {
def &&(other: Expr): Expr =
ExprUtil.reduce(Expr.and(expr, other))
def ||(other: Expr): Expr =
ExprUtil.reduce(Expr.or(expr, other))
def &&?(other: Option[Expr]): Expr =
other.map(e => &&(e)).getOrElse(expr)
def ||?(other: Option[Expr]): Expr =
other.map(e => ||(e)).getOrElse(expr)
def negate: Expr =
ExprUtil.reduce(Expr.NotExpr(expr))
def unary_! : Expr =
negate
}
object Q {
def tagIdsIn(values: NonEmptyList[String]): Expr =
Expr.TagIdsMatch(TagOperator.AnyMatch, values)
def tagIdsEq(values: NonEmptyList[String]): Expr =
Expr.TagIdsMatch(TagOperator.AllMatch, values)
def tagsIn(values: NonEmptyList[String]): Expr =
Expr.TagsMatch(TagOperator.AnyMatch, values)
def tagsEq(values: NonEmptyList[String]): Expr =
Expr.TagsMatch(TagOperator.AllMatch, values)
}
}

View File

@ -69,6 +69,9 @@ object ExprUtil {
expr
case AttachId(_) =>
expr
case ValidItemStates =>
expr
}
private def spliceAnd(nodes: Nel[Expr]): Nel[Expr] =