[英]cts:value-match on xs:dateTime() type in Marklogic
I have a variable $yearMonth := "2015-02"
I have to search this date on an element Date as xs:dateTime
. 我有一个变量
$yearMonth := "2015-02"
我必须在元素Date as xs:dateTime
上将此日期搜索Date as xs:dateTime
。 I want to use regex expression to find all files/documents having this date "2015-02-??" 我想使用正则表达式查找日期为“ 2015-02- ??”的所有文件/文档。 I have
path-range-index
enabled on ModifiedInfo/Date
I am using following code but getting Invalid cast
error 我在
ModifiedInfo/Date
上启用了path-range-index
,我正在使用以下代码,但得到了Invalid cast
错误
let $result := cts:value-match(cts:path-reference("ModifiedInfo/Date"), xs:dateTime("2015-02-??T??:??:??.????"))
I have also used following code and getting same error 我也用下面的代码,并得到相同的错误
let $result := cts:value-match(cts:path-reference("ModifiedInfo/Date"), xs:dateTime(xs:date("2015-02-??"),xs:time("??:??:??.????")))
Kindly help :) 请帮助:)
It seems you are trying to use wild card search on Path Range index which has data type xs:dateTime(). 似乎您正在尝试对路径范围索引使用通配符搜索,该索引的数据类型为xs:dateTime()。
But, currently MarkLogic don't support this functionality. 但是,当前MarkLogic不支持此功能。 There are multiple ways to handle this scenario:
有多种方法可以处理这种情况:
You may run this workaround to support your existing system: 您可以运行以下解决方法以支持现有系统:
for $x in cts:values(cts:path-reference("ModifiedInfo/Date")) return if(starts-with(xs:string($x), '2015-02')) then $x else () for $ x in cts:values(cts:path-reference(“ ModifiedInfo / Date”))返回if(starts-with(xs:string($ x),'2015-02'))然后$ x else()
This query will fetch out values from lexicon and then you may filter your desired date. 该查询将从词典中获取值,然后您可以过滤所需的日期。
You can solve this by combining a couple cts:element-range-querys inside of an and-query: 您可以通过在and-query中结合几个cts:element-range-querys来解决此问题:
let $target := "2015-02"
let $low := xs:date($target || "-01")
let $high := $low + xs:yearMonthDuration("P1M")
return
cts:search(
fn:doc(),
cts:and-query((
cts:element-range-query("country", ">=", $low),
cts:element-range-query("country", "<", $high)
))
)
From the cts:element-range-query documentation : 从cts:element-range-query文档中 :
If you want to constrain on a range of values, you can combine multiple cts:element-range-query constructors together with cts:and-query or any of the other composable cts:query constructors, as in the last part of the example below.
如果要限制值的范围,可以将多个cts:element-range-query构造函数与cts:and-query或其他任何可组合的cts:query构造函数组合在一起,如下面示例的最后一部分。
You could also consider doing a cts:values with a cts:query param that searches for values between for instance 2015-02-01 and 2015-03-01. 您也可以考虑使用cts:query参数执行cts:values来搜索例如2015-02-01和2015-03-01之间的值。 Mind though, if multiple dates occur within one document, you will need to post filter manually after all (like in option 3 of Navin), but it could potentially speed up post-filtering a lot..
请注意,如果在一个文档中出现多个日期,那么您毕竟需要手动过帐过滤器(如Navin的选项3),但这可能会大大加快后过滤的速度。
HTH! HTH!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.