Remove attach.count from query

Issue: #1758
This commit is contained in:
eikek
2022-10-23 22:32:00 +02:00
parent 195b35fb52
commit a5c84da51f
14 changed files with 2885 additions and 104 deletions

View File

@ -8,7 +8,7 @@ package docspell.query
import cats.data.{NonEmptyList => Nel}
import docspell.query.ItemQuery.Attr.{DateAttr, IntAttr, StringAttr}
import docspell.query.ItemQuery.Attr.{DateAttr, StringAttr}
/** A query evaluates to `true` or `false` given enough details about an item.
*
@ -43,7 +43,7 @@ object ItemQuery {
object Attr {
sealed trait StringAttr extends Attr
sealed trait DateAttr extends Attr
sealed trait IntAttr extends Attr
// sealed trait IntAttr extends Attr
case object ItemName extends StringAttr
case object ItemSource extends StringAttr
@ -52,7 +52,6 @@ object ItemQuery {
case object Date extends DateAttr
case object DueDate extends DateAttr
case object CreatedDate extends DateAttr
case object AttachCount extends IntAttr
object Correspondent {
case object OrgId extends StringAttr
@ -78,7 +77,7 @@ object ItemQuery {
object Property {
final case class StringProperty(attr: StringAttr, value: String) extends Property
final case class DateProperty(attr: DateAttr, value: Date) extends Property
final case class IntProperty(attr: IntAttr, value: Int) extends Property
// final case class IntProperty(attr: IntAttr, value: Int) extends Property
def apply(sa: StringAttr, value: String): Property =
StringProperty(sa, value)
@ -86,8 +85,8 @@ object ItemQuery {
def apply(da: DateAttr, value: Date): Property =
DateProperty(da, value)
def apply(na: IntAttr, value: Int): Property =
IntProperty(na, value)
// def apply(na: IntAttr, value: Int): Property =
// IntProperty(na, value)
}
sealed trait Expr {

View File

@ -72,14 +72,8 @@ object AttrParser {
val folderName: P[Attr.StringAttr] =
P.ignoreCase(C.folder).as(Attr.Folder.FolderName)
val attachCountAttr: P[Attr.IntAttr] =
P.ignoreCase(C.attachCount).as(Attr.AttachCount)
// combining grouped by type
val intAttr: P[Attr.IntAttr] =
attachCountAttr
val dateAttr: P[Attr.DateAttr] =
P.oneOf(List(date, dueDate, created))
@ -104,5 +98,5 @@ object AttrParser {
)
val anyAttr: P[Attr] =
P.oneOf(List(dateAttr, stringAttr, intAttr))
P.oneOf(List(dateAttr, stringAttr))
}

View File

@ -8,7 +8,7 @@ package docspell.query.internal
object Constants {
val attachCount = "attach.count"
// val attachCount = "attach.count"
val attachId = "attach.id"
val cat = "cat"
val checksum = "checksum"

View File

@ -83,8 +83,8 @@ object ExprString {
Right(s"${stringAttr(attr)}${opStr(op)}${quote(value)}")
case Property.DateProperty(attr, value) =>
Right(s"${dateAttr(attr)}${opStr(op)}${dateStr(value)}")
case Property.IntProperty(attr, value) =>
Right(s"${attrStr(attr)}${opStr(op)}$value")
// case Property.IntProperty(attr, value) =>
// Right(s"${attrStr(attr)}${opStr(op)}$value")
}
case TagCategoryMatch(op, values) =>
@ -171,13 +171,6 @@ object ExprString {
attr match {
case a: StringAttr => stringAttr(a)
case a: DateAttr => dateAttr(a)
case a: IntAttr => intAttr(a)
}
private[internal] def intAttr(attr: IntAttr): String =
attr match {
case AttachCount =>
Constants.attachCount
}
private[internal] def dateAttr(attr: DateAttr): String =

View File

@ -6,7 +6,6 @@
package docspell.query.internal
import cats.parse.Numbers
import cats.parse.{Parser => P}
import docspell.query.ItemQuery._
@ -26,9 +25,6 @@ object SimpleExprParser {
private[this] val inOrOpDate =
P.eitherOr(op ~ DateParser.date, inOp *> DateParser.dateOrMore)
private[this] val opInt =
op ~ Numbers.digits.map(_.toInt)
val stringExpr: P[Expr] =
(AttrParser.stringAttr ~ inOrOpStr).map {
case (attr, Right((op, value))) =>
@ -45,11 +41,6 @@ object SimpleExprParser {
Expr.InDateExpr(attr, values)
}
val intExpr: P[Expr] =
(AttrParser.intAttr ~ opInt).map { case (attr, (op, value)) =>
Expr.SimpleExpr(op, Property(attr, value))
}
val existsExpr: P[Expr.Exists] =
(P.ignoreCase(C.exist) *> P.char(C.like) *> AttrParser.anyAttr).map(attr =>
Expr.Exists(attr)
@ -114,7 +105,6 @@ object SimpleExprParser {
List(
dateExpr,
stringExpr,
intExpr,
existsExpr,
fulltextExpr,
tagIdExpr,

View File

@ -93,11 +93,8 @@ object ItemQueryGen {
val dateAttrGen: Gen[Attr.DateAttr] =
Gen.oneOf(Attr.Date, Attr.DueDate, Attr.CreatedDate)
val intAttrGen: Gen[Attr.IntAttr] =
Gen.const(Attr.AttachCount)
val attrGen: Gen[Attr] =
Gen.oneOf(stringAttrGen, dateAttrGen, intAttrGen)
Gen.oneOf(stringAttrGen, dateAttrGen)
private val valueChars =
Gen.oneOf(Gen.alphaNumChar, Gen.oneOf(" /{}*?-:@#$~+%…_[]^!ß"))
@ -105,9 +102,6 @@ object ItemQueryGen {
private val stringValueGen: Gen[String] =
Gen.choose(1, 20).flatMap(n => Gen.stringOfN(n, valueChars))
private val intValueGen: Gen[Int] =
Gen.choose(1900, 9999)
private val identGen: Gen[String] =
Gen
.choose(3, 12)
@ -167,12 +161,6 @@ object ItemQueryGen {
sval <- stringValueGen
} yield Property.StringProperty(attr, sval)
val intPropGen: Gen[Property.IntProperty] =
for {
attr <- intAttrGen
ival <- intValueGen
} yield Property.IntProperty(attr, ival)
val datePropGen: Gen[Property.DateProperty] =
for {
attr <- dateAttrGen
@ -180,7 +168,7 @@ object ItemQueryGen {
} yield Property.DateProperty(attr, dv)
val propertyGen: Gen[Property] =
Gen.oneOf(stringPropGen, datePropGen, intPropGen)
Gen.oneOf(stringPropGen, datePropGen)
val simpleExprGen: Gen[Expr.SimpleExpr] =
for {