<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/cts.plan.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>cts.plan</api:function-name><api:suggest>cts.plan</api:suggest><api:suggest>cts</api:suggest><api:suggest>plan</api:suggest><api:function mode="javascript" name="plan" type="builtin" lib="cts" category="Extension" subcategory="Search" class="javascript" hidden="false" bucket="MarkLogic Built-In Functions" prefix="cts" namespace="http://marklogic.com/cts" fullname="cts.plan"><api:summary>
  Returns an array of JavaScript objects recording information about how the
  given search will be processed by the index.  The information is a
  structured representation of the information provided in the error log
  when query trace is enabled.  The query will be processed up to the
  point of getting an estimate of the number of fragments returned by the
  index.
</api:summary><api:params><api:param name="query" type="cts:query?"><api:param-description>
    A 
    <span class="javascript" xmlns="http://www.w3.org/1999/xhtml"><code>cts.query</code></span> specifying
    the search to perform.  If a string is entered, the string is
    treated as a 
    <span class="javascript" xmlns="http://www.w3.org/1999/xhtml"><code>cts.wordQuery</code></span> 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="options" type="(cts:order|xs:string)*" optional="true"><api:param-description>
    Options to this search.  The default is 
    <span class="javascript" xmlns="http://www.w3.org/1999/xhtml">null</span>. See 
    <a href="./cts:search" xmlns="http://www.w3.org/1999/xhtml"><code>cts.search</code></a>
    for details on available options.
  </api:param-description><api:param-name>options</api:param-name><api:param-type>String[]</api:param-type></api:param><api:param name="quality-weight" type="xs:double?" optional="true"><api:param-description>
    A document quality weight to use when computing scores.
    The default is 1.0.
  </api:param-description><api:param-name>quality-weight</api:param-name><api:param-type>Number?</api:param-type></api:param><api:param name="forest-ids" type="xs:unsignedLong*" optional="true"><api:param-description>
     <span class="javascript" xmlns="http://www.w3.org/1999/xhtml">An array</span> 
    of IDs of forests to which the search will be constrained.
    An empty 
    <span class="javascript" xmlns="http://www.w3.org/1999/xhtml">array</span> means to search all forests in the database.
    The default is 
    <span class="javascript" xmlns="http://www.w3.org/1999/xhtml">[]</span>. In the XQuery version, you can use
    <code xmlns="http://www.w3.org/1999/xhtml">cts:search</code> with this parameter and an empty <code xmlns="http://www.w3.org/1999/xhtml">cts:and-query</code> 
    to specify a forest-specific XPath statement (see the
    <a href="./cts:search#searchEx3" xmlns="http://www.w3.org/1999/xhtml">third example</a> below). If you
    use this to constrain an XPath to one or more forests, you should set
    the <code xmlns="http://www.w3.org/1999/xhtml">quality-weight</code> to zero to preserve the XPath document
    order.
  </api:param-description><api:param-name>forest-ids</api:param-name><api:param-type>String[]</api:param-type></api:param><api:param name="maximum" type="xs:double?" optional="true"><api:param-description>
    The maximum value to return.
    Stop selecting fragments if this number is reached.
  </api:param-description><api:param-name>maximum</api:param-name><api:param-type>Number?</api:param-type></api:param></api:params><api:return class="javascript">Array</api:return><api:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">The output from 
  <span class="javascript"><code>cts.plan</code></span> will vary depending 
  on various index settings.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">Running a 
  <span class="javascript"><code>cts.plan</code></span> on a search is 
  similar to running an 
  <span class="javascript"><code>cts.estimate</code></span> on a search, 
  but it returns a report on the search instead of just an estimate. 
  As part of the report, the 
  <span class="javascript"><code>qry.result</code></span> element includes 
  the estimate.
  </p>
</api:usage><api:privilege>
   <code xmlns="http://www.w3.org/1999/xhtml">http://marklogic.com/xdmp/privileges/xdmp-plan</code>
</api:privilege><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
cts.plan(cts.wordQuery("cat"));
=&gt;
[
  {
    "exprTrace": "xdmp:eval(\"cts.plan(cts.wordQuery(\\\"cat\\\"));\", {}, &lt;options xmlns=\"xdmp:eval\"&gt;&lt;database&gt;18245659202902618990&lt;/database&gt;&lt;modules&gt;10742030102324...&lt;/options&gt;)"
  },
  "Analyzing path for search: fn.doc()",
  "Step 1 is searchable: fn.doc()",
  "Path is fully searchable.",
  "Gathering constraints.",
  {
    "wordTrace": {
      "text": "cat",
      "keys": [
        "12545744176132597186"
      ]
    }
  },
  "Search query contributed 1 constraint: cts.wordQuery(\"cat\", [\"lang=en\"], 1)",
  {
    "partialPlan": {
      "query": {
        "termQuery": {
          "weight": 1,
          "key": "12545744176132597186",
          "annotation": "word(\"cat\")"
        }
      }
    }
  },
  "Executing search.",
  {
    "ordering": []
  },
  {
    "finalPlan": {
      "query": {
        "andQuery": {
          "queries": [
            {
              "termQuery": {
                "weight": 1,
                "key": "12545744176132597186",
                "annotation": "word(\"cat\")"
              }
            }
          ]
        }
      }
    }
  },
  "Selected 0 fragments to filter",
  {
    "result": {
      "estimate": 0
    }
  }
]
</pre></api:example></api:function></api:function-page>