[MarkLogic Dev General] XPATH vs CTS
Damon Feldman
Damon.Feldman at marklogic.com
Fri Jun 29 09:27:28 PDT 2012
Brent,
That function is still in the product and documentation: http://docs.marklogic.com/5.0doc/docapp.xqy#display.xqy?fname=http://pubs/5.0doc/apidoc/SearchBuiltins.xml&category=SearchBuiltins&function=cts:element-query
It constrains a quer condition to the contents of an element, including it’s attributes. It does not quite have descendent-or-self semantics:
xdmp:document-insert("/test.xml", <foo>Fu</foo>)
;
/foo/descendant-or-self::foo (: returns the foo element :)
,
"----",
cts:search(doc(), cts:element-query(xs:QName("foo"), cts:element-word-query(xs:QName("foo"), "Fu"))) (: no match :)
,
"-----",
cts:search(doc(), cts:element-query(xs:QName("foo"), cts:word-query( "Fu"))) (: match :)
Damon
From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of Brent Hartwig
Sent: Friday, June 29, 2012 7:48 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] XPATH vs CTS
Hi, John, this would be useful if I could count on it.
Is there a Marklogician willing to weigh in on this?
Thank you.
-Brent
From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of John Zhong
Sent: Friday, June 29, 2012 1:16 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] XPATH vs CTS
Hi Brent,
Just FYI, there is an option in cts:element-query (and other cts query) that you can specify searching on self or child etc, which is only in the MarkLogic 3.* document. I don't know why it was removed from the newer version of MarkLogic, but it is still working. Maybe it is a good opportunity to ask MarkLogic staff why?
John
cts:element-query(
$element-name as xs:QName*,
$query as cts:query,
[$options as xs:string*]
) as cts:element-query
[cid:image001.jpg at 01CD55F2.29717380]
[cid:image002.jpg at 01CD55F2.29717380]Summary:
Returns a cts:query matching elements by name with the content constrained by the given cts:query in the second parameter. Searches for matches in the specified element and all of its children.
[cid:image002.jpg at 01CD55F2.29717380]Parameters:
[cid:image002.jpg at 01CD55F2.29717380]
$element-name : One or more element QNames to match. When multiple QNames are specified, the query matches if any QName matches.
[cid:image002.jpg at 01CD55F2.29717380]
$query : A query for the element to match.
[cid:image002.jpg at 01CD55F2.29717380]
$options (optional): Options to this query. The default is ().
Options include:
"self"
Specifies the query is satisfied in the query context element node. The query context node is the element node that satisfies the innermost cts:element-query() containing this query. If there is no such cts:element-query(), the query context node is the element node in cts:search() or cts:contains() path expression.
"child"
Specifies the query is satisfied in a child element of the query context.
"descendant"
Specifies the query is satisfied in a descendant element of the query context.
"descendant-or-child"
Specifies the query is satisfied in the query context element or a descendant element of the query context.
On Fri, Jun 29, 2012 at 2:50 AM, Brent Hartwig <bhartwig at rsicms.com<mailto:bhartwig at rsicms.com>> wrote:
With cts:query, you can force ML to use an index, and, of the two, may be the only way to use range indexes. That’s not to say ML isn’t trying its hardest to use the universal index when resolving an XPath expression. One issue I have with cts:query is when I use cts:element-query() with a recursive content model. It starts with the context node and searches all descendants. There isn’t an option to specify self instead of the default descendant-or-self.
-Brent
From: general-bounces at developer.marklogic.com<mailto:general-bounces at developer.marklogic.com> [mailto:general-bounces at developer.marklogic.com<mailto:general-bounces at developer.marklogic.com>] On Behalf Of semerau at hotmail.com<mailto:semerau at hotmail.com>
Sent: Thursday, June 28, 2012 2:32 PM
To: MarkLogic Developer Discussion
Cc: general
Subject: Re: [MarkLogic Dev General] XPATH vs CTS
Those numbers you posted are really small so you may want to run your queries in large loops to get good averages.
If your xpath is simple then the speed is probably going to be the same as with cts. But I suppose xpath could actually be a little slower than path depending on the options you are using.
I would recommend using cts to query docs out of the db and then use xpath to get what you want within the doc. Xpath can be a performance problem if you try to get too tricky. With cts it's harder to write a poorly performing query, plus it has a lot more options than xpath
Sent from my iPhone
On Jun 28, 2012, at 12:23 PM, "Danny Sinang" <d.sinang at gmail.com<mailto:d.sinang at gmail.com>> wrote:
Hello,
Can someone tell me in what situations CTS is faster than XPATH or vice versa ?
I did a little test and the results (see below) were contrary to my expectation that CTS was faster.
Regards,
Danny
============================================================================================================
1. XPATH
xdmp:estimate(/asset[assetMeta/assetType="ASSET_CONTENT_BOOK"]), xdmp:elapsed-time()
=>
<v:results v:warning="more than one root item" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:v="com.marklogic.developer.cq.view">330240 PT0.000086S</v:results>
2. CTS
import module namespace search = "http://marklogic.com/appservices/search"
at "/MarkLogic/appservices/search/search.xqy";
let $query := 'assetMeta/assetType="ASSET_CONTENT_BOOK"'
let $cts-query := cts:element-query(xs:QName("assetMeta"),
cts:element-query(xs:QName("assetType"),
cts:word-query("ASSET_CONTENT_BOOK") ) )
return xdmp:estimate(cts:search(fn:collection("assets"),
cts:element-value-query(xs:QName("assetType"), "ASSET_CONTENT_BOOK" ))), xdmp:elapsed-time()
=>
<v:results v:warning="more than one root item" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:v="com.marklogic.developer.cq.view">330240 PT0.000245S</v:results>
_______________________________________________
General mailing list
General at developer.marklogic.com<mailto:General at developer.marklogic.com>
http://community.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
General at developer.marklogic.com<mailto:General at developer.marklogic.com>
http://community.marklogic.com/mailman/listinfo/general
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20120629/1655831d/attachment-0001.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 335 bytes
Desc: image001.jpg
Url : http://developer.marklogic.com/pipermail/general/attachments/20120629/1655831d/attachment-0002.jpg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.jpg
Type: image/jpeg
Size: 332 bytes
Desc: image002.jpg
Url : http://developer.marklogic.com/pipermail/general/attachments/20120629/1655831d/attachment-0003.jpg
More information about the General
mailing list