Hi Radhika,

You are accessing only one document. In that case using xpath is likely to be 
quicker. If this lookup document is large though, you might consider chopping 
your document into small once, each containing one metadata, or using fragment 
roots for a similar effect.

You could have rewritten your cts query to something like this:

cts:search(
  //treenode,
  cts:and-query((
    cts:element-query(xs:QName("metadata"),
      cts:element-value-query(xs:QName("id"), $folder-id)
    ),
    cts:document-query($document)
  ))
)

But that is not exactly the same as your XPath. (Use CQ to experiment with it 
if you like..)

Kind regards,
Geert

-----Oorspronkelijk bericht-----
Van: [email protected] 
[mailto:[email protected]] Namens Vedavalli Radhika
Verzonden: maandag 28 februari 2011 7:35
Aan: General Mark Logic Developer Discussion
Onderwerp: [MarkLogic Dev General] Is cts:search better than xpath

We got a review comment as follows. But I am not sure if replacing the
cts:search with xpath will help us with better performance. Also
avoiding xpath reverse-axes like parent, ancestor can give us better
performance. But we will not be able to get the required node without
the parent predicate. Please validate and let us know which is the
optimized way of performing the below operation.

Purpose of the xquery: we are searching for the tree node
corresponding to the given $folder-id inside the document $document

"Avoid usage of unnecessay search and parent:: operations like,
let $folder-id = "1234"
let $folder := cts:search(//metadata/id,cts:and-query(($folder-id,
cts:document-query($document))))/parent::metadata/parent::treenode

Instead try using predicates & xpath expressions,
let $doccontent := fn:doc("/ItemTree.xml")
let $treenode := $doccontent/itemtree/treenode[metadata/id = '1234']
return $treenode"

Sample XML Format:
<itemtree>
   <metadata/>
   <treenode>
      <metadata>
        <id>1234</id>
                  ....
     </metadata>
  </treenode>
  <treenode>
  </treenode>
</itemtree>

Thanks,
Radhika.
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to