<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/cts.remainder.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>cts.remainder</api:function-name><api:suggest>cts.remainder</api:suggest><api:suggest>cts</api:suggest><api:suggest>remainder</api:suggest><api:function-link mode="xquery" fullname="cts:remainder">/apidoc/8.0/cts:remainder.xml</api:function-link><api:function mode="javascript" name="remainder" type="builtin" lib="cts" category="SearchBuiltins" subcategory="Search" hidden="false" bucket="MarkLogic Built-In Functions" prefix="cts" namespace="http://marklogic.com/cts" fullname="cts.remainder"><api:summary>
  Returns an estimated search result size for a node,
  or of the context node if no node is provided.
  The search result size for a node is the number of fragments remaining
  (including the current node) in the result sequence containing the node.
  This is useful to quickly estimate the size of a search result sequence,
  without using <code xmlns="http://www.w3.org/1999/xhtml">fn:count()</code> or <code xmlns="http://www.w3.org/1999/xhtml">xdmp:estimate()</code>.
</api:summary><api:params><api:param name="node" type="node()" optional="true"><api:param-description>
    A node. Typically this is an item in the result sequence of a
    <code xmlns="http://www.w3.org/1999/xhtml">cts:search</code> operation.  If you specify the first item
    from a <code xmlns="http://www.w3.org/1999/xhtml">cts:search</code> expression,
    then <code xmlns="http://www.w3.org/1999/xhtml">cts:remainder</code> will return an estimate of the number
    of fragments that match that expression.
  </api:param-description><api:param-name>node</api:param-name><api:param-type>Node</api:param-type></api:param></api:params><api:return>Number</api:return><api:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">This function makes it efficient to estimate the size of a search result
  and execute that search in the same query.  If you only need an estimate of
  the size of a search but do not need to run the search, then
  <a href="./xdmp:estimate"></a>
  <a href="./xdmp.estimate"><code class="javascript">xdmp.estimate</code></a>
  is more efficient.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">To return the estimated size of a search with
  
  <code class="javascript">cts.remainder</code>,
  use the first item of a
  <a href="./cts:search"></a>
  <a href="./cts.search"><code class="javascript">cts.search</code></a>
  result sequence as the
  parameter to
  <code class="javascript">cts.remainder</code>. For example, the following
  query returns the estimated number of fragments that contain the word
  "dog":</p>
  
  <pre class="javascript" xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  cts.remainder(fn.subsequence(cts.search("dog"), 1, 1)) </pre>
  <p xmlns="http://www.w3.org/1999/xhtml">
  <span class="javascript">When you take a subsequence of the
  <code>cts.search</code> result ValueIterator, </span>
  MarkLogic Server will filter all of the false-positive results
  up to the specified position, but not the false-positive results beyond
  the specified
  position. Because of this, when you
  
  <span class="javascript">increase the the number of results in the
  subsequence, the result from <code>cts.remainder</code> </span>
  might decrease
  by a larger number than the increase in position number, or it might not
  decrease at all. For example, if
  the query above returned 10, then the following query might return 9, it
  might return 10, or it might return less than 9, depending on how the
  results are dispersed throughout different fragments:</p>
  
  <pre class="javascript" xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  cts.remainder(fn.subsequence(cts.search("dog"), 2, 2)) </pre>
  <p xmlns="http://www.w3.org/1999/xhtml">If you run 
  <code class="javascript">cts.remainder</code> on a constructed node, it always
  returns 0; it is primarily intended to run on nodes that are the retrieved
  from the database (an item from a search result or an
  item from the result of an XPath expression that searches through the
  database).</p>
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
var s = cts.search("dog");
var results = new Array();
var clone = s.clone();
for (var x of fn.subsequence(s, 1, 1) ) {
  results.push(cts.remainder(x));
};
results.push(clone);
results;

=&gt; Returns the estimated number of items in the search
   for "dog" followed by the results of the search.
</pre></api:example><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
// Assume a document exist as follows:
// declareUpdate();
// xdmp.documentInsert("/test.json", {"a":"my test"});

for (var x of fn.subsequence(cts.search("my test"), 1, 1) ) {
  cts.remainder(x);
};
=&gt; 1
</pre></api:example><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
for (var a of cts.search("my test")) {
 if (cts.remainder(a) == 1) {
   xdmp.nodeUri(a);
 };
};

=&gt; /test.json
</pre></api:example></api:function></api:function-page>