From 15b15666bf069fb1b488f1cf399bf5aabb99559d Mon Sep 17 00:00:00 2001 From: eikek Date: Tue, 27 Jul 2021 17:33:13 +0200 Subject: [PATCH] Allow to use the created timestamp in item queries Refs: 925 --- .../shared/src/main/scala/docspell/query/ItemQuery.scala | 1 + .../main/scala/docspell/query/internal/AttrParser.scala | 5 ++++- .../main/scala/docspell/query/internal/Constants.scala | 2 ++ .../main/scala/docspell/query/internal/MacroParser.scala | 4 ++++ .../docspell/query/internal/SimpleExprParserTest.scala | 8 ++++++++ .../docspell/store/qb/generator/ItemQueryGenerator.scala | 2 ++ website/site/content/docs/query/_index.md | 4 +++- 7 files changed, 24 insertions(+), 2 deletions(-) diff --git a/modules/query/shared/src/main/scala/docspell/query/ItemQuery.scala b/modules/query/shared/src/main/scala/docspell/query/ItemQuery.scala index 918b6d33..082b6f44 100644 --- a/modules/query/shared/src/main/scala/docspell/query/ItemQuery.scala +++ b/modules/query/shared/src/main/scala/docspell/query/ItemQuery.scala @@ -53,6 +53,7 @@ object ItemQuery { case object ItemId extends StringAttr case object Date extends DateAttr case object DueDate extends DateAttr + case object CreatedDate extends DateAttr case object AttachCount extends IntAttr object Correspondent { diff --git a/modules/query/shared/src/main/scala/docspell/query/internal/AttrParser.scala b/modules/query/shared/src/main/scala/docspell/query/internal/AttrParser.scala index 25b92f5a..c229702e 100644 --- a/modules/query/shared/src/main/scala/docspell/query/internal/AttrParser.scala +++ b/modules/query/shared/src/main/scala/docspell/query/internal/AttrParser.scala @@ -31,6 +31,9 @@ object AttrParser { val dueDate: P[Attr.DateAttr] = P.ignoreCase(C.due).as(Attr.DueDate) + val created: P[Attr.DateAttr] = + P.ignoreCase(C.created).as(Attr.CreatedDate) + val corrOrgId: P[Attr.StringAttr] = P.ignoreCase(C.corrOrgId) .as(Attr.Correspondent.OrgId) @@ -78,7 +81,7 @@ object AttrParser { attachCountAttr val dateAttr: P[Attr.DateAttr] = - P.oneOf(List(date, dueDate)) + P.oneOf(List(date, dueDate, created)) val stringAttr: P[Attr.StringAttr] = P.oneOf( diff --git a/modules/query/shared/src/main/scala/docspell/query/internal/Constants.scala b/modules/query/shared/src/main/scala/docspell/query/internal/Constants.scala index 157cd9f8..d809b152 100644 --- a/modules/query/shared/src/main/scala/docspell/query/internal/Constants.scala +++ b/modules/query/shared/src/main/scala/docspell/query/internal/Constants.scala @@ -23,6 +23,8 @@ object Constants { val corrOrgName = "corr.org.name" val corrPersId = "corr.pers.id" val corrPersName = "corr.pers.name" + val created = "created" + val createdIn = "createdIn" val customField = "f" val customFieldId = "f.id" val date = "date" diff --git a/modules/query/shared/src/main/scala/docspell/query/internal/MacroParser.scala b/modules/query/shared/src/main/scala/docspell/query/internal/MacroParser.scala index d9c8290e..77a2a7b8 100644 --- a/modules/query/shared/src/main/scala/docspell/query/internal/MacroParser.scala +++ b/modules/query/shared/src/main/scala/docspell/query/internal/MacroParser.scala @@ -35,6 +35,9 @@ object MacroParser { val dueDateRangeMacro: P[Expr.DateRangeMacro] = dateRangeMacroImpl(C.dueIn, Attr.DueDate) + val createdDateRangeMacro: P[Expr.DateRangeMacro] = + dateRangeMacroImpl(C.createdIn, Attr.CreatedDate) + val yearDateMacro: P[Expr.YearMacro] = yearMacroImpl(C.year, Attr.Date) @@ -52,6 +55,7 @@ object MacroParser { namesMacro, dateRangeMacro, dueDateRangeMacro, + createdDateRangeMacro, yearDateMacro, corrMacro, concMacro diff --git a/modules/query/shared/src/test/scala/docspell/query/internal/SimpleExprParserTest.scala b/modules/query/shared/src/test/scala/docspell/query/internal/SimpleExprParserTest.scala index 00c7dd7f..bc18949a 100644 --- a/modules/query/shared/src/test/scala/docspell/query/internal/SimpleExprParserTest.scala +++ b/modules/query/shared/src/test/scala/docspell/query/internal/SimpleExprParserTest.scala @@ -56,6 +56,14 @@ class SimpleExprParserTest extends FunSuite with ValueHelper { p.parseAll("due<2021-03-14"), Right(dateExpr(Operator.Lt, Attr.DueDate, ld(2021, 3, 14))) ) + assertEquals( + p.parseAll("created:2021-03-14"), + Right(dateExpr(Operator.Like, Attr.CreatedDate, ld(2021, 3, 14))) + ) + assertEquals( + p.parseAll("created<2021-03-14"), + Right(dateExpr(Operator.Lt, Attr.CreatedDate, ld(2021, 3, 14))) + ) assertEquals( p.parseAll("due~=2021-03-14,2021-03-13"), Right(Expr.InDateExpr(Attr.DueDate, Nel.of(ld(2021, 3, 14), ld(2021, 3, 13)))) diff --git a/modules/store/src/main/scala/docspell/store/qb/generator/ItemQueryGenerator.scala b/modules/store/src/main/scala/docspell/store/qb/generator/ItemQueryGenerator.scala index 4e356ae2..84d36d1f 100644 --- a/modules/store/src/main/scala/docspell/store/qb/generator/ItemQueryGenerator.scala +++ b/modules/store/src/main/scala/docspell/store/qb/generator/ItemQueryGenerator.scala @@ -228,6 +228,8 @@ object ItemQueryGenerator { coalesce(tables.item.itemDate.s, tables.item.created.s).s case Attr.DueDate => tables.item.dueDate.s + case Attr.CreatedDate => + tables.item.created.s } private def stringColumn(tables: Tables)(attr: Attr.StringAttr): Column[String] = diff --git a/website/site/content/docs/query/_index.md b/website/site/content/docs/query/_index.md index 83c3a6e6..db17043a 100644 --- a/website/site/content/docs/query/_index.md +++ b/website/site/content/docs/query/_index.md @@ -88,6 +88,7 @@ These fields map to at most one value: - `id` the item id - `date` the item date - `due` the due date of the item +- `created` the date when the item was created - `attach.count` the number of attachments of the item - `corr.org.id` the id of the correspondent organization - `corr.org.name` the name of the correspondent organization @@ -124,6 +125,7 @@ Other special fields: - `f.id` for referencing custom fields by their id - `dateIn` a shortcut for a range search - `dueIn` a shortcut for a range search +- `createdIn` a shortcut for a range search - `exist` check if some porperty exists - `names` a shortcut to search in several names via `:` - `year` a shortcut for a year range @@ -469,7 +471,7 @@ attach.id=5YjdnuTAdKJ-V6ofWTYsqKV-mAwB5aXTNWE-FAbeRU58qLb Shortcuts are only a short form of a longer query and are provided for convenience. The following exist: -- `dateIn` and `dueIn` +- `dateIn`, `dueIn` and `createdIn` - `year` - `names` - `conc`