Loading TOC...

cts.reverseQuery

cts.reverseQuery(
   $nodes as Node[],
   [$weight as Number?]
) as cts.reverseQuery

Summary

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.

Parameters
$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.reverseQuery on a set of nodes, the cts.similarQuery or cts.registeredQuery components of any stored query will match all nodes.

You can serialize a cts.query to an in-memory JSON string using xdmp.toJsonString. You can persist a serialized cts.query as JSON document by converting the query to a JavaScript object and passing the object to xdmp.documentInsert. For example:

    // Convert to a JSON string
    xdmp.toJsonString(cts.wordQuery('hello'))

    // Convert to JavaScript object and save in the database. The JS object
    // is implicitly converted into a JSON object node by the call.
    xdmp.documentInsert('/my/query.json', cts.wordQuery('hello').toObject());
   

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

See Also

Example

var query = cts.wordQuery('hello');
var modelNode = xdmp.toJSON({bar:"hello"});
cts.contains(
  xdmp.toJSON(query.toObject()).root, 
  cts.reverseQuery(modelNode)
);

// 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.

Comments

    Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy