search:parse( $qtext as xs:string+, [$options as element(search:options)?], [$output as xs:string?] ) as element()?
This function parses query text according
to given options and returns the appropriate
cts:query
XML. If the query string to be parsed does not
conform to the query grammar, the behavior differs, depending on the
value of $output
:
cts:query
throws a reportable error.search:query
throws away the terms after the
location of the parse error and runs the query with the terms
before the location of the parse error, typically broadening the
query.cts:query
for parsing
text.
Parameters | |
---|---|
qtext | The query text to parse. This may be a sequence, to accommodate more complex search UI. Multiple query texts will be ANDed together. |
options | Options to define the search
grammar and control the search. See the description for
$options
for the function search:search .
|
output |
The format of the parsed query, one of
schema-element(cts:query) (default),
cts:query , search:query , or
cts:annotated-query (deprecated). See the Usage Notes
for details.
|
$output
parameter to specify one of the
following output formats. All the formats are suitable for use with
search:resolve, but "cts:query" is
most efficient if you do not need to transform or traverse the query.
Passing a cts:query object avoids an extra parsing step.
schema-element(cts:query)
: The XML serialization of
a cts:query object. Use this form if you want a cts:query but
need to transform or inspect the query tree, or if you need a
serialized query. This is the default result type.
cts:query
: A cts:query object that can be passed to
functions such as cts:search
, cts:values
,
cts:value-tuples
, xdmp:sql
,
sem:sparql
, op:when
, or their Server-Side
JavaScript equivalents, without additional modification. This form
is most efficient, but cannot be modified or traversed.
search:query
: The XML serialization of a structured
query that you can use with search:resolve
. You can
also use structured queries with the Node.js, Java, or
REST Client APIs, though the Java and Node.js APIs have query
builder interfaces that usually make a raw query unnecessary.
cts:annotated-query
: Equivalent to the output
produced by schema-element(cts:query)
, but with the
addition of annotations. THIS FORM IS DEPRECATED and will be
removed in a future release.
xquery version "1.0-ml"; import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; search:parse("tag:technology AND format:pdf", <options xmlns="http://marklogic.com/appservices/search"> <constraint name="tag"> <collection/> </constraint> <constraint name="format"> <value> <element ns="http://purl.org/dc/elements/1.1/" name="tag"/> </value> </constraint> </options> ) ==> <cts:and-query xmlns:cts="http://marklogic.com/cts"> <cts:collection-query> <cts:uri>technology</cts:uri> </cts:collection-query> <cts:element-value-query> <cts:element xmlns:_1="http://purl.org/dc/elements/1.1/">_1:tag</cts:element> <cts:text xml:lang="en">pdf</cts:text> </cts:element-value-query> </cts:and-query>
xquery version "1.0-ml"; import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; search:parse("hello tag:technology AND format:pdf", <options xmlns="http://marklogic.com/appservices/search"> <constraint name="tag"> <collection/> </constraint> <constraint name="format"> <value> <element ns="http://purl.org/dc/elements/1.1/" name="tag"/> </value> </constraint> </options>, "search:query") => the following structured query: <search:query xmlns:search="http://marklogic.com/appservices/search"> <search:and-query> <search:term-query> <search:text>hello</search:text> </search:term-query> <search:and-query> <search:collection-constraint-query> <search:constraint-name>tag</search:constraint-name> <search:uri>technology</search:uri> </search:collection-constraint-query> <search:value-constraint-query> <search:constraint-name>format</search:constraint-name> <search:text>pdf</search:text> </search:value-constraint-query> </search:and-query> </search:and-query> </search:query>