cts:search( $expression as node()*, $query as cts:query?, [$options as (cts:order|xs:string)*], [$quality-weight as xs:double?], [$forest-ids as xs:unsignedLong*] ) as node()*
Returns a relevance-ordered sequence of nodes specified by a given query.
Parameters | |
---|---|
$expression | An expression to be searched. This must be an inline fully searchable path expression. |
query |
A cts:query
specifying the search to perform. If a string is entered, the string is
treated as a cts:word-query
of the specified string.
|
options |
Options to this search. The default is ().
Options include:
|
quality-weight | A document quality weight to use when computing scores. The default is 1.0. |
forest-ids |
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 (). 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 keep the XPath document
order.
|
Queries that use cts:search
require that
the XPath expression
searched is fully searchable. A fully searchable path is one that
has no steps that are unsearchable and whose last step is searchable.
You can use the
xdmp:query-trace()
function to see if the path is fully
searchable. If there are no entries in the xdmp:query-trace()
output indicating that a step is unsearchable, and if the last step
is searchable, then that path is fully
searchable. Queries that use cts:search
on unsearchable
XPath expressions will fail with an error message. You can often make
the path expressions fully searchable by rewriting the query or adding
new indexes.
Each node that
cts:search
returns has a score with which
it is associated. To access the score, use the
cts:score
function. The nodes are returned in relevance order (most relevant to least
relevant), where more relevant nodes have a higher score.
Only one of the "filtered" or "unfiltered" options may be specified in the options parameter. If neither "filtered" nor "unfiltered", is specified then the default is "filtered".
Only one of the "score-logtfidf", "score-logtf", "score-simple", "score-random", or "score-zero" options may be specified in the options parameter. If none of "score-logtfidf", "score-logtf", "score-simple", "score-random", or "score-zero" are specified, then the default is "score-logtfidf".
Only one of the "checked" or "unchecked" options may be specified in the options parameter. If the neither "checked" nor "unchecked" are specified, then the default is "checked".
Only one of the "faceted" or "unfaceted" options may be specified in the options parameter. If the neither "faceted" nor "unfaceted" are specified, then the default is "unfaceted".
If the cts:query
specified is the
empty string (equivalent to cts:word-query("")
), then the
search returns the empty sequence.
With the cts:index-order
parameter, results with no comparable index value are always returned at the end of the ordered
result sequence.
With an XQuery "order by" clause, results with no comparable value are normally returned by MarkLogic at the end of the ordered result sequence. You can override this behavior by specifying the "empty greatest" or "empty least" modifier to the "order by" clause. See https://www.w3.org/TR/2010/REC-xquery-20101214/#id-orderby-return for how to specify "order by" clauses.
cts:search(//SPEECH, cts:word-query("with flowers")) => ... a sequence of 'SPEECH' element ancestors (or self) of any node containing the phrase 'with flowers'.
cts:search(collection("self-help")/book, cts:element-query(xs:QName("title"), "meditation"), "score-simple", 1.0, (xdmp:forest("prod"),xdmp:forest("preview"))) => ... a sequence of book elements matching the XPath expression which are members of the "self-help" collection, reside in the "prod" or "preview" forests and contain "meditation" in the title element, using the "score-simple" option.
cts:search(/some/xpath, cts:and-query(()), (), 0.0, xdmp:forest("myForest")) => ... a sequence of /some/xpath elements that are in the forest named "myForest". Note the empty and-query, which matches all documents (and scores them all the same) and the quality-weight of 0, which together make each result have a score of 0, which keeps the results in document order.
cts:search(fn:doc(), "hello", ("unfiltered", cts:index-order(cts:element-reference(xs:QName("Title"))) ) )[1 to 10] => Returns the first 10 documents with the word "hello", unfiltered, ordered by the range index on the element "Title". An element range index on Title is required for this search, otherwise it throws an exception.