<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/cts.registeredQuery.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>cts.registeredQuery</api:function-name><api:suggest>cts.registeredquery</api:suggest><api:suggest>cts</api:suggest><api:suggest>registeredquery</api:suggest><api:function-link mode="xquery" fullname="cts:registered-query">/apidoc/8.0/cts:registered-query.xml</api:function-link><api:function mode="javascript" name="registeredQuery" type="builtin" lib="cts" category="SearchBuiltins" subcategory="cts:query Constructors" hidden="false" bucket="MarkLogic Built-In Functions" prefix="cts" namespace="http://marklogic.com/cts" fullname="cts.registeredQuery"><api:summary>
  Returns a query matching fragments specified by previously registered
  queries (see <a href="./cts:register" xmlns="http://www.w3.org/1999/xhtml"><code>cts:register</code></a>).  If a
  registered query with the specified ID(s) is not found, then
  a <code xmlns="http://www.w3.org/1999/xhtml">cts:search</code> operation with an invalid
  <code xmlns="http://www.w3.org/1999/xhtml">cts:registered-query</code> throws an XDMP-UNREGISTERED
  exception.
</api:summary><api:params><api:param name="ids" type="xs:unsignedLong*"><api:param-description>
    Some registered query identifiers.
  </api:param-description><api:param-name>ids</api:param-name><api:param-type>String[]</api:param-type></api:param><api:param name="options" type="xs:string*" optional="true"><api:param-description>
    Options to this query.  The default is ().
    <p xmlns="http://www.w3.org/1999/xhtml">
      Options include:</p>
      <blockquote xmlns="http://www.w3.org/1999/xhtml"><dl>
        <dt>"filtered"</dt>
        <dd>A filtered query (the default). Filtered queries
        eliminate any false-positive results and properly resolve
        cases where there are multiple candidate matches within the same
        fragment, thereby guaranteeing
        that the results fully satisfy the original <code>cts:query</code>
        item that was registered.  This option is not currently available.</dd>
        <dt>"unfiltered"</dt>
        <dd>An unfiltered query.  Unfiltered registered queries
        select fragments from the indexes that are candidates to satisfy
        the <code>cts:query</code>.
        Depending on the original <code>cts:query</code>, the
        structure of the documents in the database, and the configuration
        of the database,
        unfiltered registered queries may result in false-positive results
        or in incorrect matches when there are multiple candidate matches
        within the same fragment.
        To avoid these problems, you should only use unfiltered queries
        on top-level XPath expressions (for example, document nodes,
        collections, directories) or on fragment roots. Using unfiltered
        queries on complex XPath expressions or on XPath expressions that
        traverse below a fragment root can result in unexpected results.
        This option is required in the current release.
        </dd>
     </dl></blockquote>
  </api:param-description><api:param-name>options</api:param-name><api:param-type>String[]</api:param-type></api:param><api:param name="weight" type="xs:double?" optional="true"><api:param-description>
    A weight for this query.
    Higher weights move search results up in the relevance
    order.  The default is 1.0. The
    weight should be between 64 and -16.
    Weights greater than 64 will have the same effect as a
    weight of 64.
    Weights less than the absolute value of 0.0625 (between -0.0625 and
    0.0625) are rounded to 0, which means that they do not contribute to the
    score.
  </api:param-description><api:param-name>weight</api:param-name><api:param-type>Number?</api:param-type></api:param></api:params><api:return>cts.registeredQuery</api:return><api:usage>
<p xmlns="http://www.w3.org/1999/xhtml">If the options parameter does not contain "unfiltered",
then an error is returned, as the "unfiltered" option is required.</p>
<p xmlns="http://www.w3.org/1999/xhtml">Registered queries are persisted as a soft state only; they can
become unregistered through an explicit direction (using
<a href="./cts:deregister"><code>cts:deregister</code></a>),
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 <code>cts:registered-query</code> code in a try/catch block
or your Java or .NET code can catch and handle the exception).</p>
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  cts.search(
    cts.registeredQuery(1234567890123456,"unfiltered"))

  =&gt; .. relevance-ordered sequence of documents
     that also matches the registered query
</pre></api:example><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
// 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; }
}

</pre></api:example></api:function></api:function-page>