<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/cts.distinctiveTerms.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>cts.distinctiveTerms</api:function-name><api:suggest>cts.distinctiveterms</api:suggest><api:suggest>cts</api:suggest><api:suggest>distinctiveterms</api:suggest><api:function-link mode="xquery" fullname="cts:distinctive-terms">/apidoc/8.0/cts:distinctive-terms.xml</api:function-link><api:function mode="javascript" name="distinctiveTerms" type="builtin" lib="cts" category="SearchBuiltins" subcategory="Search" hidden="false" bucket="MarkLogic Built-In Functions" prefix="cts" namespace="http://marklogic.com/cts" fullname="cts.distinctiveTerms"><api:summary>
  Return the most "relevant" terms in the model nodes (that is, the
  terms with the highest scores).
</api:summary><api:params><api:param name="nodes" type="node()*"><api:param-description>
    Some model nodes.
  </api:param-description><api:param-name>nodes</api:param-name><api:param-type>Node[]</api:param-type></api:param><api:param name="options" type="element()?" optional="true"><api:param-description>
    <a id="db-term-options" xmlns="http://www.w3.org/1999/xhtml"></a>
    
    <span class="javascript" xmlns="http://www.w3.org/1999/xhtml">A JavaScript</span>
    representation of the options for defining which terms to
    generate and how to evaluate them.
     The following is a sample options
    
    <span class="javascript" xmlns="http://www.w3.org/1999/xhtml">object:
    <pre xml:space="preserve">
    {
      maxTerms: 20
    }
    </pre>
    </span>

    <p xmlns="http://www.w3.org/1999/xhtml">The
    
    <span class="javascript">
    <code>cts.distinctiveTerms</code> options (which are also valid for
    <code>cts.similarQuery</code>, <code>cts.train</code>,
    and <code>cts.cluster</code>)
    </span>
    include:</p>
    <dl xmlns="http://www.w3.org/1999/xhtml">
    <dt><p>
    
    <span class="javascript"><code>maxTerms</code></span>
    </p></dt>
    <dd>An integer defining the maximum number of distinctive terms to list
    in the
    
    <span class="javascript"><code>cts.distinctiveTerms</code></span> output.
    The default is 16.
    </dd>
    <dt><p>
    
    <span class="javascript"><code>minVal</code></span>
    </p></dt>
    <dd>A double specifying the minimum value a term can
    have and still be considered a distinctive term. The default is 0.</dd>
    <dt><p>
    
    <span class="javascript"><code>minWeight</code></span></p></dt>
    <dd>A number specifying the minimum weighted term frequency a term can
    have and still be considered a distinctive term.  In general this value
    will be either 0 (include unweighted terms) or 1 (don't include unweighted
    terms). The default is 1.</dd>
    <dt><p>
    
    <span class="javascript"><code>score</code></span></p></dt>
    <dd>A string defining which scoring method to use in comparing the values
    of the terms.
    The default is <code>logtfidf</code>.  See the description of scoring
    methods in the cts:search function for more details.
    Possible values are:
      <dl>
      <dt><p><code>logtfidf</code></p></dt>
      <dd>Compute scores using the logtfidf method.</dd>
      <dt><p><code>logtf</code></p></dt>
      <dd>Compute scores using the logtf method.</dd>
      <dt><p><code>simple</code></p></dt>
      <dd>Compute scores using the simple method.</dd>
      </dl>
    </dd>
    <dt><p>
    
    <span class="javascript"><code>complete</code></span></p></dt>
    <dd>A boolean value indicating whether to return terms even if there is no
    query associated with them.  The default is <code>false</code>.</dd>
    </dl>
    <dt xmlns="http://www.w3.org/1999/xhtml"><p>
    
    <span class="javascript"><code>useDbConfig</code></span></p></dt>
    <dd xmlns="http://www.w3.org/1999/xhtml"> The options below may be used to easily target a small set of terms.
    
    <span class="javascript"><code>useDbConfig</code></span>
    is a boolean value indicating whether to use the currently configured DB options 
    as defaults (overriding the built-in ones below) to determine the terms to
    generate.  This is <code>true</code> by default. When this is 
    <code>false</code>, any options below not explicitly specified 
    take their default values as listed; they do not take the database 
    settings' values. Flags explicitly specified override defaults, whether
    built-in (listed below), or from the database configuration. 
    Flags not specified in a field apply to all fields, unless the field
    has its own setting, which will be the final value. In other words
    it's a hierarchy, with each more-specific level overriding previous
    less-specific levels.
    </dd>
    <p xmlns="http://www.w3.org/1999/xhtml">
    
    <span class="javascript">
    The options element also includes database indexing options.
    </span>
    These control which terms to use. </p>
    <p xmlns="http://www.w3.org/1999/xhtml">These database options include the following
    .  
    The default given below is the default value if
    
    <span class="javascript"><code>useDbConfig</code></span> is set
    to <code>false</code>:
    </p>
    <dl xmlns="http://www.w3.org/1999/xhtml">
    <dt><p>
    
    <span class="javascript"><code>wordSearches</code></span></p></dt>
    <dd>Include terms for the words in the node. The default is
    <code>false</code>.</dd>
    <dt><p>
    <span class="javascript"><code>stemmedSearches</code></span></p></dt>
    <dd>Define whether to include terms for the stems in the node, and at
    what level of stemming: <code>off</code>, <code>basic</code>,
    <code>advanced</code>, or <code>decompounding</code>. The default is
    <code>basic</code>.
    </dd>
    <dt><p>
    <span class="javascript"><code>wordPositions</code></span></p></dt>
    <dd>Include terms for word positions in the node. The default is
    <code>false</code>.</dd>
    <dt><p>
    <span class="javascript"><code>fastCaseSensitiveSearches</code></span></p></dt>
    <dd>Include terms for case-sensitive variations of the words in the
    node. The default is <code>false</code>.</dd>
    <dt><p>
    <span class="javascript"><code>fastDiacriticSensitiveSearches</code></span></p></dt>
    <dd>Include terms for diacritic-sensitive variations of the words in
    the node.  The default is <code>false</code>.</dd>
    <dt><p>
    <span class="javascript"><code>fastPhraseSearches</code></span></p></dt><dd>Include
    terms for two-word phrases in the node.  The default is
    <code>true</code>.</dd>
    <dt><p>
    <span class="javascript"><code>phraseThroughs</code></span></p></dt><dd>If phrase
    terms are included, include terms for phrases that cross the given
    elements.  The default is to have no such elements.
    <span class="javascript">This will accept either a single string or
    an array of strings.</span></dd>
    <dt><p>
    <span class="javascript"><code>phraseArounds</code></span></p></dt><dd>If phrase
    terms are included, include terms for phrases that skip over the
    given elements.  The default is to have no such elements.
    <span class="javascript">This will accept either a single string or
    an array of strings.</span></dd>
    <dt><p>
    <span class="javascript"><code>fastElementWordSearches</code></span></p></dt>
    <dd>Include terms for words in particular elements.  The default is
    <code>true</code>.</dd>
    <dt><p>
    <span class="javascript"><code>fastElementPhraseSearches</code></span></p></dt>
    <dd>Include terms for phrases in particular elements. The default is
    <code>true</code>.</dd>
    <dt><p>
    <span class="javascript"><code>elementWordPositions</code></span></p></dt>
    <dd>Include terms for element word positions in the node. The default is
    <code>false</code>.</dd>
    <dt><p>
    <span class="javascript"><code>elementWordQueryThroughs</code></span></p></dt>
    <dd>Include terms for words in sub-elements of the given elements. The
    default is to have no such elements. 
    <span class="javascript">This will accept either a single string or
    an array of strings.</span></dd>
    <dt><p>
    <span class="javascript"><code>fastElementCharacterSearches</code></span></p></dt>
    <dd>Include terms for characters in particular elements.  The default is
    <code>false</code>.</dd>
    <dt><p>
    <span class="javascript"><code>rangeElementIndexes</code></span></p></dt>
    <dd>Include terms for data values in specific elements.  The default is
    to have no such indexes. <span class="javascript">Eg (a single element):
    <pre xml:space="preserve">
        "rangeElementIndexes": {
            "scalarType":"anyURI",
            "qname":"{http://example.com/somewhere}reporting",
            "collation":"http://marklogic.com/collation/codepoint",
            "rangeValuePositions": false,
            "invalidValues":"ignore"
        }
     </pre>
    </span>

</dd>
    <dt><p>
    <span class="javascript"><code>rangeFieldIndexes</code></span></p></dt>
    <dd>Include terms for data values in specific fields.  The default is
    to have no such indexes.

<span class="javascript">Eg (a single element):
    <pre xml:space="preserve">
        "rangeFieldIndexes": {
            "scalarType":"anyURI",
            "fieldName":"{http://example.com/place}sales",
            "collation":"http://marklogic.com/collation/codepoint",
            "rangeValuePositions": false,
            "invalidValues":"ignore"
        }
     </pre>
    </span>

</dd>
    <dt><p>
    <span class="javascript"><code>rangeElementAttributeIndexes</code></span></p></dt>
    <dd>Include terms for data values in specific attributes.  The default
    is to have no such indexes.
    <span class="javascript"> Eg (array form):
    <pre xml:space="preserve">
    "rangeElementAttributeIndexes": [
            {
                "scalarType": "decimal",
                "rangeValuePositions": true,
                "parentQname": "{http://organization.org/specs}/part",
                "qname": "{http://internet.net}/xyz"
            },
            {
                "scalarType": "anyURI",
                "collation":"http://marklogic.com/collation/",
                "rangeValuePositions": true,
                "parentQname": "{http://example.com}path",
                "qname": "{http://example.com/place}otherpath"
            },
            {
                "scalarType": "int",
                "rangeValuePositions": true,
                "parentQname": "{http://example.com}path",
                "qname": "{http://example.com/place}otherpath"
            }
        ]
     </pre>
     </span>

</dd>
    <dt><p>
    <span class="javascript"><code>oneCharacterSearches</code></span></p></dt>
    <dd>Include terms for single character.  The default is
    <code>false</code>.</dd>
    <dt><p>
    <span class="javascript"><code>twoCharacterSearches</code></span></p></dt>
    <dd>Include terms for two-character sequences. The default is
    <code>false</code>.</dd>
    <dt><p>
    <span class="javascript"><code>threeCharacterSearches</code></span></p></dt>
    <dd>Include terms three-character sequences.  The default is
    <code>false</code>.</dd>
    <dt><p>
    <span class="javascript"><code>trailingWildcardSearches</code></span></p></dt>
    <dd>Include terms for trailing wildcards. The default is
    <code>false</code>.</dd>
    <dt><p>
    
    <span class="javascript"><code>fastElementTrailingWildcardSearches</code></span>
    </p></dt>
    <dd>If trailing wildcard terms are included, include terms for
    trailing wildcards by element.  The default is <code>false</code>.</dd>
    <dt><p>
    <span class="javascript"><code>fields</code></span></p></dt>
    <dd>Include terms for the defined fields.  The default is to have
    no fields.

    <span class="javascript">The JavaScript version of these options mostly
    follows the XQuery version, but there are differences. Any property
    that can take multiple items will accept either an array of that kind of item,
    or a single item, where that item might be a string or an object containing
    sub-options. Also, where in XQuery you specify namespace and localname separately
    for URIs, in JavaScript they are combined into a qname.<br/>

    The "fields" property takes an array with the following properties:
    <dl>
      <dt><code>fieldName</code></dt>
      <dd>The name of a field to look through.</dd>
      <dt><code>includeRoot</code></dt>
      <dd>A boolean, <code>true</code> by default. Whether to look 
      through the field everywhere it appears in the XML document. Mutually 
      exclusive with specifying <code>fieldPaths</code>.</dd>
      <dt><code>fieldPaths</code></dt>
      <dd>Lets you be selective about where the given field must appear 
      in order to be searched through. Contains a path and how much weight 
      to give items found in <code>fieldName</code>s at this path. Eg:
    <pre xml:space="preserve">
    "fieldPaths": [
      {
        "path":"/root/child/grandchild",
        "weight":3.4
      },
      {
        "path":"/other/location",
        "weight":2.6
      }
    ]
    </pre>
    Mutually exclusive with setting <code>includeRoot</code>.
      </dd>

      <dl>
      <dt>The following are same as the general options above, except 
      restricted to this field. All are <code>false</code> by default:</dt>
      <dd><code>stemmedSearches</code></dd>
      <dd><code>wordSearches</code></dd>
      <dd><code>fastCaseSensitiveSearches</code></dd>
      <dd><code>fastDiacriticSensitiveSearches</code></dd>
      <dd><code>fastPhraseSearches</code></dd>
      <dd><code>trailingWildcardSearches</code></dd>
      <dd><code>trailingWildcardWordPositions</code></dd>
      <dd><code>oneCharacterSearches</code></dd>
      <dd><code>twoCharacterSearches</code></dd>
      <dd><code>threeCharacterSearches</code></dd>
      <dd><code>threeCharacterWordPositions</code></dd>
      </dl>

      <dt><code>wordLexicons</code></dt>
      <dd>A single string or array of strings containing the name(s) 
      of lexicons to use.</dd>

      <dt><code>includedElements</code></dt>
      <dd>
    <pre xml:space="preserve">
      Eg:
      "includedElements": {
          "qname":"{http://organization.org}first/second",
          "attributeQname":"{http://somewhere.com}visibility",
          "attributeValue":"public",
          "weight":1.2
      }
    </pre>
      </dd>

      <dt><code>excludedElements</code></dt>
      <dd>
    <pre xml:space="preserve">
    Eg:
    "excludedElements": [
        {
            "qname":"{http://organization.org}first/second",
            "attributeQname":"{http://internet.net}importance",
            "attributeValue":"notimportant"
        },
        {
            "qname":"{http://company.com}first/second",
            "attributeQname":"{http://somewhere.com}visibility",
            "attributeValue":"internal"
        }
    ]
    </pre>
      </dd>
    </dl>
    </span>
    </dd>
  </dl>
</api:param-description><api:param-name>options</api:param-name><api:param-type>Node?</api:param-type></api:param></api:params><api:return class="javascript">Object</api:return><api:usage>
<a id="output_format" xmlns="http://www.w3.org/1999/xhtml"><b>Output Format</b></a>
The output of the function is a  <span class="javascript" xmlns="http://www.w3.org/1999/xhtml">class object</span> containing

<span class="javascript" xmlns="http://www.w3.org/1999/xhtml">an array</span> of 

<span class="javascript" xmlns="http://www.w3.org/1999/xhtml">term objects.</span> (This is the same as the weights form of a class for
the SVM classifier; see <span class="javascript" xmlns="http://www.w3.org/1999/xhtml">cts.train</span>.)  Each 
<span class="javascript" xmlns="http://www.w3.org/1999/xhtml">term object</span> identifies the term ID as well
as a score, confidence, and fitness measure for the term, in addition
to a 
<span class="javascript" xmlns="http://www.w3.org/1999/xhtml">cts.query</span> that corresponds to
the term.  The correspondence of terms to queries is not precise:
queries typically make use of multiple terms, and not all terms
correspond to a query. However, a search using the query given for a
term will match the model node that gave rise to it.
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
cts.distinctiveTerms( fn.doc("/a.xml").toArray(),
{
  score: "logtfidf"
});
=&gt; a cts:class element
</pre></api:example><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
cts.distinctiveTerms(
    [fn.doc('/shakespeare/plays/hamlet.xml')],
    {
        "maxTerms":2,
        "minVal": 6,
        "minWeight": 5,
        "score":"logtfidf",
        "useDbConfig":false,
        "complete":true,
        "elementWordPositions":true,
        "fastCaseSensitiveSearches":true,
        "fastDiacriticSensitiveSearches":true,
        "fastElementCharacterSearches":true,
        "fastElementPhraseSearches":true,
        "fastElementTrailingWildcardSearches":true,
        "fastElementWordSearches":true,
        "fastPhraseSearches":true,
        "fastReverseSearches":true,
        "language":"en",
        "oneCharacterSearches":false,
        "stemmedSearches":"decompounding",
        "threeCharacterSearches":false,
        "trailingWildcardSearches":false,
        "twoCharacterSearches":false,
        "wordPositions":true,
        "wordSearches":true,
        // array form
        "elementWordQueryThroughs": ["{http://foobar.com/quux}x",
                                     "i","b"],
        // single-element form
        "phraseArounds": "div",
        "phraseThroughs": "{http://example.com/stoneville}xavier",

        "fields":[
            {
                "fieldName": "dave",
                // "includeRoot":true,
                "fieldPaths": {
                    "path":"/root/child/grandchild",
                    "weight":3
                },
                "stemmedSearches":true,
                "wordSearches":true,
                "fastCaseSensitiveSearches":true,
                "fastDiacriticSensitiveSearches":true,
                "fastPhraseSearches":true,
                "trailingWildcardSearches":true,
                "trailingWildcardWordPositions":true,
                "oneCharacterSearches":true,
                "twoCharacterSearches":true,
                "threeCharacterSearches":true,
                "threeCharacterWordPositions":true,
                "wordLexicons":["http://marklogic.com/collation/codepoint"],
                "includedElements": {
                    "qname":"{http://marklogic.com}fish",
                    "attributeQname":"{http://marklogic.com}bill",
                    "attributeValue":'13',
                    "weight":17
                },
                "excludedElements": [{
                    "qname":"{http://marklogic.com}pete",
                    "attributeQname":"{http://marklogic.com}sam",
                    "attributeValue":'14',
                }]
            }
        ],
         // single-element form
        "rangeElementIndexes": {
            "scalarType":"anyURI",
            "qname":"{http://example.org/xyzzy}dave",
            "collation":"http://marklogic.com/collation/codepoint",
            "rangeValuePositions": false,
            "invalidValues":"ignore"
        },
        // array form
        "rangeElementAttributeIndexes": [
            {
                "scalarType": "decimal",
                "rangeValuePositions": true,
                "parentQname": "{http://marklogic.com/quux}brad",
                "qname": "{http://marklogic.com/stoneville}marble"
            },
            {
                "scalarType": "anyURI",
                "collation":"http://marklogic.com/collation/",
                "rangeValuePositions": true,
                "parentQname": "{http://marklogic.com/quux}brad",
                "qname": "{http://marklogic.com/stoneville}marble"
            },
            {
                "scalarType": "int",
                "rangeValuePositions": true,
                "parentQname": "{http://marklogic.com/quux}brad",
                "qname": "{http://marklogic.com/stoneville}marble"
            }
        ],
        // single-element array
        "rangeFieldIndexes": [{
            "scalarType":"anyURI",
            "fieldName":"{http://example.org/xyzzy}dave",
            "collation":"http://marklogic.com/collation/codepoint",
            "rangeValuePositions": false,
            "invalidValues":"ignore"
        }],
    }
);
==&gt;
{
  "name":"dterms /shakespeare/plays/hamlet.xml",
  "offset":0,
  "terms":[
    {
      "id":"17190342381662130619",
      "val":825,
      "score":1689600,
      "confidence":1,
      "fitness":0,
      "query":{
        "wordQuery":{
          "text":[
            "hamlet"
          ],
          "options":[
            "case-insensitive",
            "diacritic-insensitive",
            "stemmed",
            "unwildcarded",
            "lang=en"
          ]
        }
      }
    },
    {
      "id":"14936670113463358967",
      "val":791,
      "score":202496,
      "confidence":1,
      "fitness":1,
      "query":{
        "elementValueQuery":{
          "element":[
            "SPEAKER"
          ],
          "text":[
            "HAMLET"
          ],
          "options":[
            "diacritic-insensitive",
            "stemmed",
            "unwildcarded",
            "lang=en"
          ]
        }
      }
    }
  ]
}
</pre></api:example></api:function></api:function-page>