cts.elementRangeQuery( element-name as xs.QName[], operator as String, value as (String | Number | Boolean | null | Array | Object)[], [options as String[]], [weight as Number?] ) as cts.elementRangeQuery
Constructs a query that matches elements by name with range index entry equal to a given value. Searches that use an element range query require an element range index on the specified QName(s); if no such range index exists, then an exception is thrown.
To constrain on a range of values, combine multiple element range
queries together using
cts.andQuery
or any of the
composable query constructors, as in the last part of the example below.
If neither "cached" nor "uncached" is present, it specifies "cached".
The "cached-incremental" option can improve performance if you repeatedly perform range queries on date or dateTime values over a short range that does not vary widely over short period of time. To benefit, the operator should remain the same "direction" (<,<=, or >,>=) across calls, the bounding date or dateTime changes slightly across calls, and the query runs very frequently (multiple times per minute). Note that using this options creates significantly more cached queries than the "cached" option.
The "cached-incremental" option has the following restrictions and interactions: The "min-occurs" and "max-occurs" options will be ignored if you use "cached-incremental" in unfiltered search. You can only use "score-function=zero" with "cached-incremental". The "cached-incremenal" option behaves like "cached" if you are not querying date or dateTime values.
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.
// create a document with test data declareUpdate(); xdmp.documentInsert('/dates.xml', xdmp.unquote('<root>\n\ <entry>\n\ <date>2007-01-01</date>\n\ <info>Some information.</info>\n\ </entry>\n\ <entry>\n\ <date>2006-06-23</date>\n\ <info>Some other information.</info>\n\ </entry>\n\ <entry>\n\ <date>1971-12-23</date>\n\ <info>Some different information.</info>\n\ </entry>\n\ </root>')); // ***** Example Search 1 // requires an element (range) index of // type xs.date on 'date' const res = []; for (const x of cts.search( cts.elementRangeQuery(xs.QName('date'), '<=', xs.date('2000-01-01')))){ res.push(x.xpath('/root/entry')); }; res; // returns an array containing the following node: // [ // <entry> // <date>1971-12-23</date> // <info>Some different information.</info> // </entry> // ] // ***** Example Search 2 // requires an element (range) index of // type xs:date on 'date' const res = new Array(); for (const x of cts.search( cts.andQuery(( cts.elementRangeQuery(xs.QName('date'), '>', xs.date('2006-01-01')), cts.elementRangeQuery(xs.QName('date'), '<', xs.date('2008-01-01'))))) ) { res.push(x.xpath('/root/entry')); } res; // Returns an array with 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>