2

Is it possible to search for a uri whose document contains a certain XPath using cts:uris()? I thought it may be quicker than returning uris from a cts:search. Here is what I have currently:

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) 
} ;

Is there a quicker way to return documents that contain a match to the XPath //a/b, using cts:uris()?

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
cascavel
  • 191
  • 1
  • 7
  • You could eliminate the FLWOR and just use: `cts:search(//a/b, cts:and-query((cts:collection-query($collection) )) )/fn:base-uri() ` – Mads Hansen Jul 04 '16 at 18:48

1 Answers1

2

You can use cts:element-query() to construct a cts:query that functions similar to the XPath expression //a/b searching for documents that have a elements that have b element descendants. It isn't exactly the same, and might give you some false positives, because it is really more akin to //a//b, but might be acceptable and can be used with 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(()) ) ) )) )
};
Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
  • If you are willing to create a path range index, you can use that in the same way in replacement of the nested cts:element-queries, but needing those path indexes makes that a less flexible approach.. – grtjn Jul 05 '16 at 13:47