在 Marklogic Xquery 中删除少于 30 天的文档 [英] Delete documents less than 30 days in Marklogic Xquery

查看:24
本文介绍了在 Marklogic Xquery 中删除少于 30 天的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个日期时间字段,我必须删除少于 30 天的文档.如何在 xquery 中实现如日期时间字段<30 天.

I have a datetime field, I have to delete documents less than 30 days. How can that be acheived in xquery like datetimefield<30 days.

推荐答案

在搜索日期时间范围时,范围索引将是最好/最快的.

When searching for dateTime ranges, a range-index would be the best/fastest.

使用 dateTime 元素范围索引,您可以执行以下操作:

With a dateTime element-range index you can do something like this:

let $thirtyDaysAgo := current-dateTime() - xs:dayTimeDuration("P30D")
return
  cts:search(doc(), 
    cts:and-query((
      cts:element-range-query(xs:QName("myDateTimeField"), ">", $thirtyDaysAgo),
      cts:element-range-query(xs:QName("myDateTimeField"), "<", current-dateTime())
    ))

如果您没有范围索引,那么您可以搜索包含该字段的文档并对搜索结果应用谓词过滤器(希望尽可能缩小候选的数量,甚至可以寻找几年以及将作为该字段中的单词包含在该日期范围内的月份)

If you don't have a range index, then you could search for documents that contain that field and apply a predicate filter to the search results (hopefully narrowing down the number of candidates as much as possible, maybe even looking for years and months that would be included in that date range as words within that field)

cts:search(doc(), 
  cts:element-query(xs:QName("myDateTimeField"), cts:true-query())
)[.//myDateTimeField[xs:dateTime(.) gt $thirtyDaysAgo and xs:dateTime(.) lt current-dateTime()]]

但是,如果从搜索中返回了很多候选词,则使用谓词进行过滤可能会很慢.使用更具体的 XPath 来定位该元素而不是 // 后代轴也可能略有帮助.

However, filtering with the predicate can be slow if there are a lot of candidates returned from the search. Using a more specific XPath to target that element instead of // descendant axis might also help slightly.

这篇关于在 Marklogic Xquery 中删除少于 30 天的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆