Loading TOC...

MarkLogic Server 11.0 Product Documentation
cts:range-query

cts:range-query(
   $index as cts:reference*,
   $operator as xs:string,
   $value as xs:anyAtomicType*,
   [$options as xs:string*],
   [$weight as xs:double?]
) as cts:range-query

Summary

Returns a cts:query matching specified nodes with a range-index entry compared to a given value. Searches with the cts:range-query constructor require a range index; if there is no range index configured, then an exception is thrown.

Parameters
index One or more range index references. When multiple indexes are specified, the query matches if any index 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. When multiple values are specified, the query matches if any value matches.
options Options to this query. The default is ().

Options include:

"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:range-query constructors together with cts:and-query or any of the other composable cts:query constructors, as in the last part of the example below.

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.

Example

(: create a document with test data :)
xdmp:document-insert("/dates.xml",
<root>
  <entry>
    <date>2007-01-01</date>
    <info>Some information.</info>
  </entry>
  <entry>
    <date>2006-06-23</date>
    <info>Some other information.</info>
  </entry>
  <entry>
    <date>1971-12-23</date>
    <info>Some different information.</info>
  </entry>
</root>);

(:
   requires a range index of
   type xs:date on element "date"
:)
cts:search(doc("/dates.xml")/root/entry,
  cts:range-query(cts:element-reference(xs:QName("date")), "<=",
      xs:date("2000-01-01")))
(:
  returns the following node:
  <entry>
    <date>1971-12-23</date>
    <info>Some different information.</info>
  </entry>
:)
;
(:
   requires a range index of
   type xs:date on element "date"
:)
cts:search(doc("/dates.xml")/root/entry,
  cts:and-query((
   cts:range-query(cts:element-reference(xs:QName("date")), ">",
      xs:date("2006-01-01")),
   cts:range-query(cts:element-reference(xs:QName("date")), "<",
      xs:date("2008-01-01")))))
(:
  returns the following 2 nodes:
  <entry>
    <date>2007-01-01</date>
    <info>Some information.</info>
  </entry>

  <entry>
    <date>2006-06-23</date>
    <info>Some other information.</info>
  </entry>
:)

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