我有一个Oracle查询,想转换成Marklogic cts查询。看起来Marklogic CTS不允许在“and-query”中包含“and-query”。我不确定Marklogic的工作原理。提前谢谢。
Where子句查询:
where (collection = "TRBA" AND fulltext = 1
AND (dnta = "Briefing" OR dnta = "Conference" OR snta = "Workshop"
OR snta = "Published in" AND (snta = "this article" OR dnta = "Journal")
)
AND (cand IN ("Research","Development Center") OR scn IN("424778","98814","393825"))
转换为Marklogic:
let $uris:= cts:uris(
(),
(),
cts:and-query((
cts:collection-query("/dbs/"TRBA"),
cts:element-value-query(xs:QName("meta:FullTextExists"),"1"),
cts:field-word-query("dnta",("briefing","conference")),
cts:or-query((
cts:element-word-query(xs:QName("meta:snta"),("this article")),
cts:field-word-query("dnta",("Journal")),
cts:and-query((
cts:or-query((
cts:field-word-query("cand", ("Research","Development Center"))
cts:field-word-query("scn",("424778","98814","393825"))
))
))(:inside and-query:)
))(:or-query:)
))(:outside and-query:)
return fn:doc($uris)
答案 0 :(得分:4)
cts:parse
,其中包含ANDs和OR等字符串以及字段绑定,并将查询字符串解析为cts:query
那就是说,如果你假设与OR混合的AND绑定到最近的子句,即括号括起来:
(collection = "TRBA" AND
fulltext = 1 AND
(dnta = "Briefing" OR
dnta = "Conference" OR
snta = "Workshop" OR
(snta = "Published in" AND (snta = "this article" OR dnta = "Journal"))
) AND
(cand IN ("Research","Development Center") OR
scn IN ("424778","98814","393825"))
然后我会翻译这样的东西:
cts:and-query((
cts:collection-query("/dbs/TRBA"),
cts:element-value-query(xs:QName("meta:FullTextExists"),"1"),
cts:or-query((
cts:field-value-query("dnta",("Briefing","Conference")),
cts:field-value-query("snta","Workshop"),
cts:and-query((
cts:field-value-query("snta","Published in"),
cts:or-query((
cts:field-value-query("snta","this article"),
cts:field-value-query("dnta","Journal")
))
))
)),
cts:or-query((
cts:field-value-query("cand",("Research","Development Center")),
cts:field-value-query("scn",("424778","98814","392825"))
))
))
这是一个非常直接的映射。
答案 1 :(得分:2)
您的代码中只有几个拼写错误。 collection-query
中有一个额外的双引号,并且您在上一个or-query
中的项目之间缺少逗号。
修复后,代码就会运行。但专业提示:不要只提取URI来获取文档。你在浪费精力。只需通过传递查询的搜索来直接获取文档。
let $q := cts:and-query((...))
return cts:search(doc(), $q)[1 to 10]
除非您真的打算返回完整的结果集,否则您可能希望添加[1 to 10]
之类的限制。