繁体   English   中英

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

[英]How to list all the URI of all documents in a directory in marklogic

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

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

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

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

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

怎么样:

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

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

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

如果您启用URI Lexicon,那么您可以做得更好。 这是xmlsh marklogic“ls”命令的源代码...嵌入其中的是相当简单的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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM