search.values( spec-name as String, options as element(search.options), [query as element(search.query)?], [limit as (Number|String)?], [start as xs.anyAtomicType?], [page-start as (Number|String)?], [page-length as (Number|String)?] ) as element(search.valuesResponse)
This function returns lexicon values and co-occurrences, and allows you to calculate aggregates based on the lexicon values.
Parameters | |
---|---|
spec-name | The name of a values in the Search Developer's Guide or tuples in the Search Developer's Guide specification in the supplied options node. |
options |
Options that define and control the query. The options must
include the $spec-name definitions supplied in the first parameter.
The following is a list of the options that affect lexicon queries;
the options node can contain other options, but they are not used.
For details, see
Appendix: Query Options Reference in the Search Developer's Guide.
|
query | A structured query to apply as a constraint when retrieving lexicon values. |
limit | The maximum number of values to return. The default is no limit. |
start |
A starting value in the lexicon. If the $start is
not present in the lexicon, the values
are returned starting with the next value in the range index
after where $start would logically appear. If no
$start value is supplied, values are returned
beginning with the first value in the lexicon.
|
page-start |
The index of the first value to return from within the subset
defined by limit and start . Default: 1.
|
page-length |
The number of values to return within the subset of values
defined by limit and start . Default:
Return all values.
|
const search = require('/MarkLogic/appservices/search/search'); const options = fn.head(xdmp.unquote('<options xmlns="http://marklogic.com/appservices/search">' + '<values name="uri">' + '<uri/>' + '<aggregate apply="min"/>' + '</values>' + '</options>')).root; search.values('uri', options); // ==> // <values-response name="uri" type="xs:string" // xmlns="http://marklogic.com/appservices/search" // xmlns:xs="http://www.w3.org/2001/XMLSchema"> // <distinct-value frequency="2">/date.xml</distinct-value> // <distinct-value frequency="2">/gajanan.xml</distinct-value> // <distinct-value frequency="2">/test/keys.json</distinct-value> // <aggregate-result name="min">/date.xml</aggregate-result> // <metrics> // <values-resolution-time>PT0.000193S</values-resolution-time> // <aggregate-resolution-time>PT0.000409S</aggregate-resolution-time> // <total-time>PT0.001987S</total-time> // </metrics> // </values-response>
const search = require('/MarkLogic/appservices/search/search'); const options = fn.head(xdmp.unquote('<search:options xmlns:search="http://marklogic.com/appservices/search">' + '<values name="animals">' + '<range type="xs:string">' + '<field name="animal-name" collation="http://marklogic.com/collation/" />' + '</range>' + '</values>' + '</search:options>')).root; search.values('animals', options, search.parse('mammal OR marsupial', null, 'search:query'), 10, 'camel', 5, 3); /* Assuming the value subset defined by the query (mammal OR marsupial), limit (10), and start ("buffalo") contains the values (camel, fox, hare, jaguar, kangaroo, lemur, moose, ocelot, panda, rhino), then adding a page-start of 5 and a page-length of 3, you get the following: <values-response name="animals" type="xs:string" xmlns="http://marklogic.com/appservices/search" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <distinct-value frequency="1">kangaroo</distinct-value> <distinct-value frequency="1">lemur</distinct-value> <distinct-value frequency="1">moose</distinct-value> <metrics> <values-resolution-time>PT0.000242S</values-resolution-time> <total-time>PT0.00134S</total-time> </metrics> </values-response> */