<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/cts.aggregate.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>cts.aggregate</api:function-name><api:suggest>cts.aggregate</api:suggest><api:suggest>cts</api:suggest><api:suggest>aggregate</api:suggest><api:function-link mode="xquery" fullname="cts:aggregate">/apidoc/8.0/cts:aggregate.xml</api:function-link><api:function mode="javascript" name="aggregate" type="builtin" lib="cts" category="SearchBuiltins" subcategory="Math Lexicon" hidden="false" bucket="MarkLogic Built-In Functions" prefix="cts" namespace="http://marklogic.com/cts" fullname="cts.aggregate"><api:summary>
  Executes a user-defined extension aggregate function against
  a value lexicon or n-way co-occurence of multiple value lexicons.
  Value lexicons are implemented using range indexes; consequently
  this function requires a range index for each lexicon specified
  in the function. If a specified range index does not exist an error is raised.
  If the "ordered" or "proximity=" option is specified, the
  range index must have range value positions set to true, otherwise an
  error is raised.
</api:summary><api:params><api:param name="native-plugin" type="xs:string"><api:param-description>
    The path to the native plugin library containing the implementation of the
    user-defined extension aggregate.
  </api:param-description><api:param-name>native-plugin</api:param-name><api:param-type>String</api:param-type></api:param><api:param name="aggregate-name" type="xs:string"><api:param-description>
    The name of an aggregate function in <code xmlns="http://www.w3.org/1999/xhtml">$native-plugin</code>.
  </api:param-description><api:param-name>aggregate-name</api:param-name><api:param-type>String</api:param-type></api:param><api:param name="range-indexes" type="cts:reference*"><api:param-description>
    A sequence of references to range indexes.  The first range index specified in this or any other
    aggregate function cannot be of type "nullable".
  </api:param-description><api:param-name>range-indexes</api:param-name><api:param-type>cts.reference[]</api:param-type></api:param><api:param name="argument" type="item()*" optional="true"><api:param-description>
    A sequence containing the arguments for the aggregate function. A map
    can be used to pass in multiple sequences of arguments.
  </api:param-description><api:param-name>argument</api:param-name><api:param-type>ValueIterator</api:param-type></api:param><api:param name="options" type="xs:string*" optional="true"><api:param-description>
    options.  The default is ().
    <p xmlns="http://www.w3.org/1999/xhtml">
      Options include:</p>
      <blockquote xmlns="http://www.w3.org/1999/xhtml"><dl>
        <dt>"any"</dt>
        <dd>Co-occurrences from any fragment should be included.</dd>
        <dt>"document"</dt>
        <dd>Co-occurrences from document fragments should be included.</dd>
        <dt>"properties"</dt>
        <dd>Co-occurrences from properties fragments should be included.</dd>
        <dt>"locks"</dt>
        <dd>Co-occurrences from locks fragments should be included.</dd>
        <dt>"fragment-frequency"</dt>
        <dd>Frequency should be the number of fragments with
        an included co-occurrences.
        This option is used with <code>cts:frequency</code>.</dd>
        <dt>"item-frequency"</dt>
        <dd>Frequency should be the number of occurences of
        an included co-occurrence.
        This option is used with <code>cts:frequency</code>.</dd>
        <dt>"ordered"</dt>
        <dd>Include co-occurrences only when the value from the first lexicon
        appears before the value from the second lexicon.
        Requires that word positions be enabled for both lexicons.</dd>
        <dt>"proximity=<em>N</em>"</dt>
        <dd>Include co-occurrences only when the values appear within
        <em>N</em> words of each other.
        Requires that word positions be enabled for both lexicons.</dd>
        <dt>"checked"</dt>
        <dd>Word positions should be checked when resolving the query.</dd>
        <dt>"unchecked"</dt>
        <dd>Word positions should not be checked when resolving the query.</dd>
        <dt>"too-many-positions-error"</dt>
        <dd>If too much memory is needed to perform positions calculations
        to check whether a document matches a query, 
        return an XDMP-TOOMANYPOSITIONS error, 
        instead of accepting the document as a match.</dd>
        <dt>"concurrent"</dt>
        <dd>Perform the work concurrently in another thread. This is a hint
        to the query optimizer to help parallelize the lexicon work, allowing
        the calling query to continue performing other work while the lexicon
        processing occurs.  This is especially useful in cases where multiple
        lexicon calls occur in the same query (for example, resolving many
        facets in a single query).</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="query" type="cts:query?" optional="true"><api:param-description>
    Only include co-occurrences in fragments selected by the 
    <code xmlns="http://www.w3.org/1999/xhtml">cts:query</code>,
    and compute frequencies from this set of included co-occurrences.
    The co-occurrences do not need to match the query, but they must occur in
    fragments selected by the query.
    The fragments are not filtered to ensure they match the query,
    but instead selected in the same manner as <a href="#unfiltered" xmlns="http://www.w3.org/1999/xhtml">
    "unfiltered" <code>cts:search</code></a> operations.  If a string
   is entered, the string is treated as a <code xmlns="http://www.w3.org/1999/xhtml">cts:word-query</code> of the
   specified string.
  </api:param-description><api:param-name>query</api:param-name><api:param-type>cts.query?</api:param-type></api:param><api:param name="forest-ids" type="xs:unsignedLong*" optional="true"><api:param-description>
    A sequence of IDs of forests to which the search will be constrained.
    An empty sequence means to search all forests in the database.
    The default is ().
  </api:param-description><api:param-name>forest-ids</api:param-name><api:param-type>String[]</api:param-type></api:param></api:params><api:return>ValueIterator</api:return><api:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">Only one of "fragment-frequency" or "item-frequency" may be specified
  in the options parameter.  If neither "fragment-frequency" nor
  "item-frequency" is specified, then the default is "fragment-frequency".</p>
  <p xmlns="http://www.w3.org/1999/xhtml">Only one of "any", "document", "properties", or "locks"
  may be specified in the options parameter.
  If none of "any", "document", "properties", or "locks" are specified
  and there is a $query parameter, then the default is "document".
  If there is no $query parameter then the default is "any".</p>
  <p xmlns="http://www.w3.org/1999/xhtml">Only one of the "checked" or "unchecked" options may be specified
  in the options parameter.
  If neither "checked" nor "unchecked" are specified,
  then the default is "checked".</p>
  <p xmlns="http://www.w3.org/1999/xhtml">For details, see
 <a href="/guide/search-dev/aggregate#id_53331">Using Aggregate User-Defined Functions</a> in the <em>Search Developer's Guide</em>.</p>
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
//    This query assumes an element range index is configured
//    in the database for the 'Amount' element and that a plugin module 
//    installed under native/samplePlugin contains a UDF named "myAvg".

cts.aggregate("native/samplePlugin, "myAvg",
  cts.elementReference(xs.QName("Amount"), "type=decimal"),
  null, ["fragment-frequency","concurrent"]);

=&gt; 1410.23914666667
</pre></api:example></api:function></api:function-page>