如何选择最近 7 天内的所有文档?

发布于 2024-07-14 05:34:39 字数 142 浏览 13 评论 0原文

我有一个视图选择公式

SELECT @If( @Date(@Now) = @Date(@Created); @All; @False)  

,我希望它选择过去 7 天内的所有文档,而不仅仅是今天的文档。

I have a view selection formula

SELECT @If( @Date(@Now) = @Date(@Created); @All; @False)  

and I want it to select all documents from the past 7 days rather than just today's.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

眼波传意 2024-07-21 05:34:39

你需要 2 个部分。
视图选择公式:

SELECT isnotyet7daysOld = @True

以及一个(或两个)代理程序,该代理程序按计划并在“创建或更改文档时”运行。 代理看起来像这样(两者)

minDate := @Adjust(@Today;0;0;-7;0;0;0);
REM "There are no future documents";
tmpResult := @if(minDate <= @Created;@False;@True);
SELECT tmpResult != isnotyet7daysOld;
FIELD isnotyet7daysOld := tmpResult

对于调整,您需要 0 不为空; null 恰好可以工作,因为没有名称为 null 的字段或变量,并且 @Formula 是宽容的并将缺失值设为 0。
这里的技巧:您计算所选文档的字段 isnotyet7daysOld 应该具有的值(这将是 onChange 代理或计划代理上的所有更改的文档),然后选择仅更改这些文档结果不匹配的地方。 这样可以最大限度地减少文档更新。 保存的文档也会直接更新。 如果您现在添加一个隐藏的计算时组合字段 isnotyet7daysOld 并使用 @True 作为字段值,您可以可靠地捕获所有文档。 并且您只需每晚 (0:01) 运行一次预定的代理。

You need 2 parts.
The view selection formula:

SELECT isnotyet7daysOld = @True

and an agent (or two) which run on schedule and on "when documents have been created or changed". The agent looks like this (both)

minDate := @Adjust(@Today;0;0;-7;0;0;0);
REM "There are no future documents";
tmpResult := @if(minDate <= @Created;@False;@True);
SELECT tmpResult != isnotyet7daysOld;
FIELD isnotyet7daysOld := tmpResult

For adjust you need 0 not null; null happens to work since there is no field or variable with the name null and @Formula is forgiving and makes the missing value 0.
The trick here: you compute the value that the field isnotyet7daysOld should have for the selected documents (that would be the changed ones for the onChange agent or all on the scheduled agent) and then select to change only those where the result doesn't match. This way you minimize document updates. Also documents that get saved are updated directly. If you now add a hidden computed-when-composed field isnotyet7daysOld with @True as field value you capture all your document reliably. And you need to run the scheduled agent only once a night (0:01).

つ低調成傷 2024-07-21 05:34:39
SELECT @If( @Date(@Now) < @Date(@Adjust(@Created(), null, null, 7, null, null, null)); @All; @False)
SELECT @If( @Date(@Now) < @Date(@Adjust(@Created(), null, null, 7, null, null, null)); @All; @False)
治碍 2024-07-21 05:34:39

这是我所做的(我使用 @TextToTime("Today") 而不是 @Today 来避免根据上述警告重建索引):

SELECT (@Created) >= @Adjust(@TextToTime("Today");0;0;-7;0;0;0)   

顺便说一句,感谢上述提示。 我长期以来一直想创建一个这样的视图。 我是 az/OS 系统程序员(大型机),并且必须每周重建此视图才能使其保持最新状态,因为“固定”视图设计公式不是相对日期。 我从 Notes 帮助中的 @Created 示例中获取了 @TextToTime 提示(这有一个获取当月文档的示例)。 我的 Notes 客户端版本为 6.5。

Here is what I did (I used @TextToTime("Today") instead of @Today to avoid the index rebuild per above warning):

SELECT (@Created) >= @Adjust(@TextToTime("Today");0;0;-7;0;0;0)   

BTW, thanks for the above hints. I've been wanting to create a view like this for a long time. I'm a z/OS system programmer (mainframe) and kept having to rebuild this view weekly to get it current since the "canned" view design formula was not a relative date. I took the @TextToTime hint from the @Created example in Notes help (this had an example of getting documents in the current month). My Notes client is release 6.5.

岁吢 2024-07-21 05:34:39

您需要非常小心其中包含日期的视图选择公式。

如果您使用 @Today 或 @Now,那么 Notes/Domino 将始终认为视图中的所有文档都没有数据,并且每次访问时都必须重建索引。 这对于非常小的数据库来说还可以,但对于较大的数据库来说却是一场灾难。

有些人会尝试使用 @date("Today") 等公式来解决这个问题。 Notes/Domino 不会将其识别为基于日期/时间的公式,因为它不包含 @Today 或 @Now,并且最初会起作用。 但您会发现,除非索引完全刷新,否则视图不会删除旧文档,这可能很难安排。

处理此问题的最佳方法是让代理每晚运行,用正确的固定日期值更新选择公式。 codestore.net 的 Jake Howlett 有一些 关于执行此操作的优秀帖子

You need to be very careful of view selection formula that have dates in them.

If you use @Today or @Now then then Notes/Domino will always consider all of the documents in the view to be out of data and will have to rebuild the index every time it is accessed. This will be ok for very small databases, but a disaster in larger ones.

Some people will try and work around that by using a formula like @date("Today"). Notes/Domino will not recognise that as a Date/Time based formula, since it doesn't contain @Today or @Now, and will work initially. But you will find that the view will not remove old documents unless the index is fully refreshed, which can be tricky to arrange for.

The best way to deal with this is to have an agent run every night that updates the selection formula with the correct fixed date values. Jake Howlett at codestore.net has some excellent posts on doing this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文