Loading TOC...


   $nodes as node()*,
   [$weight as xs:double?]
) as cts:reverse-query


Construct a query that matches serialized cts queries, based on a set of model input nodes. A serialized query matches if it would match the model nodes. Use with a cts:search or cts:contains over serialized cts:query nodes.

nodes Model nodes that must be matchable by queries matched by this reverse query. See the Usage Notes for more details.
weight A weight for this query. This parameter has no effect because a reverse query does not contribute to score. That is, the score is always 0.

Usage Notes

A reverse query matches serialized cts:query nodes. Construct a reverse query from nodes that model what that serialized query should match, rather than passing in the target query. For example, to match queries for the word "hello", specify a node containing the word "hello" as the nodes parameter. See the example, below. Reverse queries are useful for creating alerting applications.

When evaluating a cts:reverse-query on a set of nodes, the cts:similar-query or cts:registered-query components of any stored query will match all nodes.

You can create a node or document containing a serialized cts:query in XQuery by wrapping a cts:query constructor in an XML node. For example, the following snippet creates an XML element (foo) that contains a serialized word query:

    <foo>{cts:word-query("my search")}</foo>/element()

A reverse query can match both the XML and JSON representations of a serialized query.

See Also


let $content := <query>{cts:word-query("hello")}</query>
let $model-node := <bar>hello</bar>
cts:contains($content, cts:reverse-query($model-node))
   Returns true because the content contains a cts:word-query
   for "hello", which would match the model node. Here, the content is
   an in-memory node, but it could also be a document (or node) in the

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.