I'm worried about scalability in a large database and other xquery conversions have really increased performance.
What I'm trying now is to build the cts query string dynamically where I can use 'if then else' to add the necessary cts syntax, and then do xdmp:eval() on the string in cts:search. A simple test seemed to work ok. Does that make sense? Gary -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Michael Blakeley Sent: Monday, April 16, 2012 11:53 AM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] simple cts constructor for variable check The quick answer is something like: if ($oc) then () else cts:element-value-query(xs:QName(nv:objectClass), $oc) When $oc is empty, there is no need to include that query term at all. So it can be empty too. However, the long answer is that converting an XPath expression to cts:query won't necessarily improve performance. If you don't need composability or relevance ranking, you might as well stick with XPath. But trying to express an XPath as a cts:query can be a useful exercise, because anything that won't map easily is likely to be expensive and anything that can be expressed in cts:query is likely to be efficient. It is tricky to say exactly what is going on without profiler output, but I imagine that the expensive bits of your XPath are probably the nested steps. For example: $oc = nv:lookupInfo/nv:objectClass nvdiff:diff/nv:content/nv:crnData8[nv:policies or nv:members] Wherever possible you want to rearrange the XPath steps so that they are searchable and flat. Here's a slightly more efficient version: xdmp:directory("/db/netvisn/audit_history/", "infinity")/ nv:auditHistory[not($oc) or $oc = nv:lookupInfo/nv:objectClass]/ nv:audit[ $effect ne "spec" or nv:sync/nv:archived] [$effect ne "security" or nvdiff:diff/nv:content/nv:crnData8/(nv:policies | nv:members)] -- Mike On 16 Apr 2012, at 08:21 , Gary Larsen wrote: > Hi > > I'm trying to convert a query to use cts for performance. Is there a cts constructor that I can use the check a variable? > > Here's a portion of the query: > > xdmp:directory('/db/netvisn/audit_history/','infinity') > /nv:auditHistory > [fn:not(fn:exists($oc)) or $oc = nv:lookupInfo/nv:objectClass] > /nv:audit > [$effect ne 'spec' or nv:sync/nv:archived] > [$effect ne 'security' ornvdiff:diff/nv:content/nv:crnData8[nv:policies or nv:members]] > > > For example I would like to turn this portion into a cts:or-query > > $effect ne 'spec' or nv:sync/nv:archived > > For second part I can use a cts:element-value-query(). I need something for the first part. > > Or maybe I'm looking at this all wrong. Thanks for any suggestions. > > Gary > > _______________________________________________ > General mailing list > [email protected] > http://developer.marklogic.com/mailman/listinfo/general _______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general _______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
