
cts.search( query as cts.query?, [options as String[]], [quality-weight as Number?], [forestIds as (xs.unsignedLong|[xs.unsignedLong])?] ) as Sequence
Returns a relevance-ordered sequence of nodes specified by a given query.
| 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 ().
Options include:
|
| quality-weight | A document quality weight to use when computing scores. The default is 1.0. |
| forestIds |
An ID or an array of IDs of forests to which the search will be constrained.
A value of null or empty array means to search all forests in the database.
The default is null.
|
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", "score-zero", or "score-bm25" options may be specified in the options parameter. If none of "score-logtfidf", "score-logtf", "score-simple", "score-random", "score-zero", or "score-bm25" 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.wordQuery("")), then the
search returns an empty Iterator.
Only one of "any", "document", "properties", or "locks" may be specified in the options parameter. If none of "any", "document", "properties", or "locks" are specified and there is a $query parameter, then the default is "document". If there is no $query parameter then the default is "any".
With the cts.indexOrder
parameter, results with no comparable index value are always returned at the end of the ordered
result sequence.
If "bm25-length-weight=NUMBER" is provided along with the "score-bm25" option, the BM25 scoring method is used with the weight specified. If the "score-bm25" option is provided but "bm25-length-weight=NUMBER" is not specified, the default value is 0.333. If provided, the value must be greater than 0.0 and less than or equal to 1.0. This value is used to calculate the BM25 score of each search result, and determines how much of an effect the document length to average document length ratio has on this score. Use lower values for "bm25-length-weight=NUMBER" to push the scores in favor of log(term frequency) and higher values to push the scores in favor of (document length / average document length). The optimal value for "bm25-length-weight=NUMBER" depends on your document collection. Experiment with this value to receive results that best fit your application.
cts.search(cts.wordQuery("with flowers"));
=> ... an Iterator of any node containing the phrase 'with flowers'.
fn.subsequence(cts.search(cts.wordQuery("with flowers")), 1, 10);
=> ... an Iterator of the first 10 nodes containing the phrase 'with flowers'.
'use strict';
cts.search(
cts.trueQuery(),
null,
null,
[xdmp.forest("myForest")]
)
=> ... an Iterator of documents stored in the forest named "myForest".
Note that the query matches all documents (and scores them all the same)
and the quality-weight of null (or 0), together make each result have
a score of 0. This combination keeps the results in document order.
fn.subsequence(
cts.search("hello", ["unfiltered",
cts.indexOrder(cts.elementReference(fn.QName("", "Title")))
] ), 1, 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.
'use strict';
let scr = 'score-bm25'
let fct = 'unfaceted'
let lw = 'bm25-length-weight=0.25'
var list = []
for (let doc of cts.search(
cts.nearQuery(
(cts.wordQuery(["poison","potion"],"synonym"),
cts.wordQuery(["king","duke"],"synonym")),1),
[scr,fct,"relevance-trace",lw])) {
list.push(cts.relevanceInfo(doc))
}
list;
=> Returns the relevance information of the BM25 search results
with a BM25 length weight of 0.25
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.