cts:reverse-query( $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.
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.
let $content := <query>{cts:word-query("hello")}</query> let $model-node := <bar>hello</bar> return 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 database. :)