cts.registeredQuery( ids as (Number|String)[], [options as String[]], [weight as Number?] ) as cts.registeredQuery
Returns a query matching fragments specified by previously registered
queries (see cts:register
). If
the database is not empty and a registered query with the specified ID(s)
is not found, then a cts:search
operation with an invalid
cts:registered-query
throws an XDMP-UNREGISTERED exception.
Searches that use registered queries will generate results with different scores than the equivalent searches using non-registered queries. This is because registered queries are treated as a single term in relevance calculations.
If the options parameter does not contain "unfiltered", then an error is returned, as the "unfiltered" option is required.
Registered queries are persisted as a soft state only; they can
become unregistered through an explicit direction (using
cts:deregister
),
as a result of the cache growing too large, or because of a server restart.
Consequently, either your XQuery code or your middleware layer should handle
the case when an XDMP-UNREGISTERED exception occurs (for example, you can
wrap your cts:registered-query
code in a try/catch block
or your Java or .NET code can catch and handle the exception).
Unfiltered queries, including registered queries, do not match in cts.walk or cts.highlight.
cts.search( cts.registeredQuery(1234567890123456,"unfiltered")) => .. relevance-ordered sequence of documents that also matches the registered query
// wrap the registered query in a try/catch try { cts.search(cts.registeredQuery(995175721241192518,"unfiltered")) } catch (e) { if (e.name == "XDMP-UNREGISTERED") { fn.concat("Retry this query with the following registered query ID: ", xdmp.eval('cts.register(cts.wordQuery("hello*world","wildcarded"))')) } else { e; } }
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.