如何列出marklogic目录中所有文档的所有URI

时间:2014-10-01 10:50:33

标签: xquery marklogic

您如何检索目录中所有文档的URI。我创建了下面的xquery来实现这一目标,但这并没有帮助。

for $i in xdmp:directory("/Test/performance/results/","infinity")
let $k := document-uri(fn:doc($i))
return <li>{$k}</li>

3 个答案:

答案 0 :(得分:10)

为了提高效率,您应该使用URI词典。

cts:uris((), (), cts:directory-query("/Test/performance/results/","infinity"))

有关文档,请参阅https://docs.marklogic.com/cts:uris

答案 1 :(得分:1)

怎么样:

xdmp:directory("/Test/performance/results/","infinity") !
    <li>{fn:document-uri(.)}</li>

答案 2 :(得分:0)

海报XQuery不正确,因为$ i已经是一个文件而不是一个URI 所以运行fn:doc($ i)是行不通的。

亚当的解决方案将起作用(为了深入),但可能会非常缓慢 获取每个文档。在大型数据库上非常慢。

如果您启用了URI Lexicon,那么您可以做得更好。 这是xmlsh marklogic&#34; ls&#34;的源代码。嵌入其中的命令是相当简单的XQuery。

https://github.com/DALDEI/xmlsh/blob/master/extensions/marklogic/src/org/xmlsh/marklogic/ls.xsh

相关代码:

xquery version "1.0-ml";
declare variable $root external;
for $p in fn:distinct-values( 
    for $d in cts:uris($root,"document", 
          if( $root eq "" ) then () else cts:directory-query($root,"infinity"))
    let $p := substring-after( $d , $root )
    where $d ne $root 
    return 
       if( contains($p,"/") ) then fn:concat($root , substring-before( $p , "/" ) , "/" )
    else 
       concat($root ,$p) 
    )
where $p eq "" or $p ne $root
return $p 

这仅列出使用uri词典

的目录的直接子项

这个程序有点复杂 - 它尝试使用uri词典但是如果它失败则恢复到xdmp:目录......它根据-r标志列出直接或递归

https://github.com/DALDEI/xmlsh/blob/master/extensions/marklogic/src/org/xmlsh/marklogic/list.xsh