Loading TOC...

cts.plan

cts.plan(
   query as cts.query?,
   [options as String[]],
   [quality-weight as Number?],
   [forest-ids as (Number|String)[]],
   [maximum as Number?]
) as Array

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.

Parameters
query A cts.query specifying the search to perform. If a string is entered, the string is treated as a cts.wordQuery of the specified string.
options Options to this search. The default is null. See cts.search for details on available options.
quality-weight A document quality weight to use when computing scores. The default is 1.0.
forest-ids An array of IDs of forests to which the search will be constrained. An empty array means to search all forests in the database. The default is []. In the XQuery version, you can use cts:search with this parameter and an empty cts:and-query to specify a forest-specific XPath statement (see the third example below). If you use this to constrain an XPath to one or more forests, you should set the quality-weight to zero to preserve the XPath document order.
maximum The maximum value to return. Stop selecting fragments if this number is reached.

Required Privileges

http://marklogic.com/xdmp/privileges/xdmp-plan

Usage Notes

The output from cts.plan will vary depending on various index settings.

Running a cts.plan on a search is similar to running an cts.estimate on a search, but it returns a report on the search instead of just an estimate. As part of the report, the qry.result element includes the estimate.

Example

cts.plan(cts.wordQuery("cat"));
=>
[
  {
    "exprTrace": "xdmp:eval(\"cts.plan(cts.wordQuery(\\\"cat\\\"));\", {}, <options xmlns=\"xdmp:eval\"><database>18245659202902618990</database><modules>10742030102324...</options>)"
  },
  "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
    }
  }
]

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.