Loading TOC...

cts.pathRangeQuery

cts.pathRangeQuery(
   $path-expression as String[],
   $operator as String,
   $value as any[],
   [$options as String[]],
   [$weight as Number?]
) as cts.pathRangeQuery

Summary

Returns a cts:query matching documents where the content addressed by an XPath expression satisfies the specified relationship (=, <, >, etc.) with respect to the input criteria values. A path range index must exist for each path when you perform a search.

Parameters
$path-expression One or more XPath expressions that identify the content to match. When multiple paths are specified, the query matches if any path matches.
$operator A comparison operator.

Operators include:

"<"
Match range index values less than $value.
"<="
Match range index values less than or equal to $value.
">"
Match range index values greater than $value.
">="
Match range index values greater than or equal to $value.
"="
Match range index values equal to $value.
"!="
Match range index values not equal to $value.
$value One or more values to match. These values are compared to the value(s) addressed by the path-expression parameter. When multiple When multiple values are specified, the query matches if any value matches. The value must be a type for which there is a range index defined.
$options Options to this query. The default is ().

Options include:

"collation=URI"
Use the range index with the collation specified by URI. If not specified, then the default collation from the query is used. If a range index with the specified collation does not exist, an error is thrown.
"cached"
Cache the results of this query in the list cache.
"uncached"
Do not cache the results of this query in the list cache.
"min-occurs=number"
Specifies the minimum number of occurrences required. If fewer that this number of words occur, the fragment does not match. The default is 1.
"max-occurs=number"
Specifies the maximum number of occurrences required. If more than this number of words occur, the fragment does not match. The default is unbounded.
"score-function=function"
Use the selected scoring function. The score function may be:
linear
Use a linear function of the difference between the specified query value and the matching value in the index to calculate a score for this range query.
reciprocal
Use a reciprocal function of the difference between the specified query value and the matching value in the index to calculate a score for this range query.
zero
This range query does not contribute to the score. This is the default.
"slope-factor=number"
Apply the given number as a scaling factor to the slope of the scoring function. The default is 1.0.
"synonym"
Specifies that all of the terms in the $value parameter are considered synonyms for scoring purposes. The result is that occurrences of more than one of the synonyms are scored as if there are more occurrences of the same term (as opposed to having a separate term that contributes to score).
$weight A weight for this query. The default is 1.0.

Usage Notes

If you want to constrain on a range of values, you can combine multiple cts:path-range-query constructors together with cts:and-query or any of the other composable cts:query constructors.

If neither "cached" nor "uncached" is present, it specifies "cached".

Negative "min-occurs" or "max-occurs" values will be treated as 0 and non-integral values will be rounded down. An error will be raised if the "min-occurs" value is greater than the "max-occurs" value.

"score-function=linear" means that values that are further away from the bounds will score higher. "score-function=reciprocal" means that values that are closer to the bounds will score higher. The functions are scaled appropriately for different types, so that in general the default slope factor will provide useful results. Using a slope factor greater than 1 gives distinct scores over a smaller range of values, and produces generally higher scores. Using a slope factor less than 1 gives distinct scores over a wider range of values, and produces generally lower scores.

Use cts.rangeQuery if you need to include namespace bindings in your path range query.

Example

// Insert few documents with test data.  Requires a
// path (range) index of type xs:string on path "/name/fname".

declareUpdate();
xdmp.documentInsert("/aname1.xml", fn.head(xdmp.unquote(
  '<name><fname>John</fname><mname>Rob</mname><lname>Goldings</lname></name>')
   ));
xdmp.documentInsert("/aname2.xml", fn.head(xdmp.unquote(
  '<name><fname>Jim</fname><mname>Ken</mname><lname>Kurla</lname></name>')
  ));
xdmp.documentInsert("/aname3.xml", fn.head(xdmp.unquote(
  '<name><fname>Ooi</fname><mname>Ben</mname><lname>Fu</lname></name>')
  ));
xdmp.documentInsert("/aname4.xml", fn.head(xdmp.unquote(
  '<name><fname>James</fname><mname>Rick</mname><lname>Tod</lname></name>')
  ));

*****
// Requires a path (range) index of type xs:string on path "/name/fname".

cts.contains(fn.doc(),cts.pathRangeQuery("/name/fname","=","John"))
 => true

cts.search(cts.pathRangeQuery("/name/fname",">","Jim"),"filtered");
 =>
<?xml version="1.0" encoding="UTF-8"?>
<name><fname>John</fname><mname>Rob</mname><lname>Goldings</lname></name>
<?xml version="1.0" encoding="UTF-8"?>
<name><fname>Ooi</fname><mname>Ben</mname><lname>Fu</lname></name>

cts.search(cts.pathRangeQuery("/name/fname","<","John"),"unfiltered");
 =>
<?xml version="1.0" encoding="UTF-8"?>
<name><fname>Jim</fname><mname>Ken</mname><lname>Kurla</lname></name>
<?xml version="1.0" encoding="UTF-8"?>
<name><fname>James</fname><mname>Rick</mname><lname>Tod</lname></name>

Comments

    Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy