MarkLogic:如何使用cts:uri搜索XPath



是否可以使用cts:uris()搜索其文档包含特定XPath的uri ?我想这可能比从cts:search返回uri要快。以下是我目前的内容:

declare function local:xpath-search($collection)  {
 for $i in cts:search(//a/b, cts:and-query((cts:collection-query($collection)) ))[1] return fn:base-uri($i) 
} ;

是否有一种更快的方法来返回包含与XPath //a/b匹配的文档,使用cts:uris() ?

可以使用cts:element-query()构造一个cts:查询,其功能类似于XPath表达式//a/b,用于搜索具有b元素后代的a元素的文档。它并不完全相同,并且可能会给您一些误报,因为它实际上更类似于//a//b,但可能是可以接受的,并且可以与cts:uris()一起使用。

xquery version "1.0-ml";
declare function local:xpath-search($collection)  {
  cts:uris("", (), 
    cts:and-query(( 
      cts:collection-query($collection),
      cts:element-query(xs:QName("a"), 
        cts:element-query(xs:QName("b"), cts:and-query(()) ) ) )) )
};

最新更新