In XQuery, you import not only the core Optic library
import module namespace op="http://marklogic.com/optic"
at "/MarkLogic/optic.xqy";
but also the libraries that provide any expression functions that needed in the query. Use any combination of the following libraries:
import module namespace octs="http://marklogic.com/optic/expression/cts"
at "/MarkLogic/optic/optic-cts.xqy";
import module namespace ofn="http://marklogic.com/optic/expression/fn"
at "/MarkLogic/optic/optic-fn.xqy";
import module namespace ogeo="http://marklogic.com/optic/expression/geo"
at "/MarkLogic/optic/optic-geo.xqy";
import module namespace ojson="http://marklogic.com/optic/expression/json"
at "/MarkLogic/optic/optic-json.xqy";
import module namespace omap="http://marklogic.com/optic/expression/map"
at "/MarkLogic/optic/optic-map.xqy";
import module namespace omath="http://marklogic.com/optic/expression/math"
at "/MarkLogic/optic/optic-math.xqy";
import module namespace ordf="http://marklogic.com/optic/expression/rdf"
at "/MarkLogic/optic/optic-rdf.xqy";
import module namespace osem="http://marklogic.com/optic/expression/sem"
at "/MarkLogic/optic/optic-sem.xqy";
import module namespace ospell="http://marklogic.com/optic/expression/spell"
at "/MarkLogic/optic/optic-spell.xqy";
import module namespace osql="http://marklogic.com/optic/expression/sql"
at "/MarkLogic/optic/optic-sql.xqy";
import module namespace oxdmp="http://marklogic.com/optic/expression/xdmp"
at "/MarkLogic/optic/optic-xdmp.xqy";
import module namespace oxs="http://marklogic.com/optic/expression/xs"
at "/MarkLogic/optic/optic-xs.xqy";
Thereafter, you call the functions in the same way with the important difference that the arguments can include not only literals but op:col("NAME")
to specify column values or the return values from other, nested expression functions as in:
=> op:where(
ofn:starts-with(
op:col("col1"),
ofn:substring-before(op:col("col2"), "prefix")
)
)
Note that you only use the functions from the Optic expression libraries when operating on values during execution of the query. To operate on literal values passed as arguments when building the plan, use the ordinary functions.
In particular, cts:query() arguments are always constructed in the cts
namespace and not the octs
namespace.
For details about what functions are exposed as expression functions and about how expression functions are exposed in SJS, see also: https://stackoverflow.com/a/65924267/1091497
Hoping that helps,
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…