[MarkLogic Dev General] filtering in XQuery
James A. Robinson
jim.robinson at stanford.edu
Wed Dec 27 10:12:51 PST 2006
I have a question which touches on a thread from a few days ago, on
'sorting efficency question'. We're exploring using XML files to store
metadata in a URI hierarchy. One thing we will need to be able to do
is take potentially large result sets (e.g., 'find me all the children
under this branch in the hierarchy') and filter the results.
It seemed obvious that we could program the actual selection of data
directly using MarkLogic specific functions. However, we'd also like
to be able to use this hierarchy outside of MarkLogic (e.g., exporting
portions of the tree to a filesystem with a Saxon based engine serving
We've tried to tackle this in two phases, and I was wondering if anyone
on the list has done anything similar, and might have comments regarding
what did (or did not) work well. First, an outline of what we are doing:
Right now we've defined a simple WXS which declares a simple XML language
for declaring what kind of items are of interest. For example, calling
a series of 'selector compose' functions we've written:
might result in the following 'filter' document:
<sel:period scale="1" test="ge"/>
telling us we are interested in documents published in the year
year 1997 and which specify that they are in french.
I've written a basic set of evaluator functions to walk the above tree,
testing each terminal node (sel:period, sel:after, sel:before, and
sel:lang) for a match, returning true() or false() as necessary,
short circuiting as appropriate for AND, OR, and NOT, etc.
But it seems like it'd be much better if, when executing within MarkLogic
Server, I could take advantage of cts:search. I could quickly, I think,
write a function which takes the above selector document and turn it
into a cts query. I was thinking this might then be used as a 'set'
with which to handle the filtering.
The kicker is, I'd like very much to be able to use either evaluator
module, the 'basic' one or the MarkLogic one, based on which environment
I'm in. Is the only way I can see to do this is to have main modules
which statically declare an import for one or the other. Is there a
dynamic way to resolve which file I want to import?
If XQuery were in XML like XSLT I'd just write a stylesheet to process the
import directives as needed for export into the non-MarkLogic environment!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
James A. Robinson jim.robinson at stanford.edu
Stanford University HighWire Press http://highwire.stanford.edu/
+1 650 7237294 (Work) +1 650 7259335 (Fax)
More information about the General