<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/cts.similarQuery.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>cts.similarQuery</api:function-name><api:suggest>cts.similarquery</api:suggest><api:suggest>cts</api:suggest><api:suggest>similarquery</api:suggest><api:function-link mode="xquery" fullname="cts:similar-query">/apidoc/8.0/cts:similar-query.xml</api:function-link><api:function mode="javascript" name="similarQuery" 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.similarQuery"><api:summary>
  Returns a query matching nodes similar to the model nodes.  It uses an
  algorithm which finds the most "relevant" terms in the model nodes
  (that is, the terms with the highest scores), and then creates a
  query equivalent to a <code xmlns="http://www.w3.org/1999/xhtml">cts:or-query</code> of those terms.  By default
  16 terms are used.
</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="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:param name="options" type="element()?" optional="true"><api:param-description>
    
    <span class="javascript" xmlns="http://www.w3.org/1999/xhtml">An object containing</span> 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</span>:
    
    <pre xml:space="preserve" class="javascript" xmlns="http://www.w3.org/1999/xhtml"><br/>
    {
      maxTerms: 20
    }
    </pre>

    
    <p class="javascript" xmlns="http://www.w3.org/1999/xhtml">See 
    <a href="/cts.distinctiveTerms#db-term-options">the
    <code>cts.distinctiveTerms</code>
    options</a> for the valid options to use with this function.</p>
    <p xmlns="http://www.w3.org/1999/xhtml">Note that enabling index settings that
    are disabled in the database configuration will not affect the results,
    as similar documents will not be found on the basis of terms that do
    not exist in the actual database index.</p>

  </api:param-description><api:param-name>options</api:param-name><api:param-type>Node?</api:param-type></api:param></api:params><api:return>cts.similarQuery</api:return><api:usage>
   As the number of fragments in a database grows, the results
   of 
   <span class="javascript" xmlns="http://www.w3.org/1999/xhtml"><code>cts.similarQuery</code></span> become 
   increasingly accurate. For best results, there should be at least 10,000 
   fragments for 32-bit systems, and 1,000 fragments for 64-bit systems.
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  // Note that although the API is defined as taking string
  // representations of nodes, MarkLogic will automatically convert
  // sequences of nodes to an array of their string representation
  // when required.
  cts.search(
    cts.similarQuery(fn.doc("nodes-like-this.xml"),
                     2,
                     {
                       maxTerms: 20
                     }
                    )
    );
=&gt; the number of fragments containing any node similar
   to 'nodes-like-this.xml'.
</pre></api:example></api:function></api:function-page>