Loading TOC...

search:values

search:values(
   $spec-name as xs:string,
   $options as element(search:options),
   [$query as element(search:query)?],
   [$limit as xs:unsignedLong?],
   [$start as xs:anyAtomicType?],
   [$page-start as xs:unsignedLong?],
   [$page-length as xs:unsignedLong?]
) as element(search:values-response)

Summary

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.

  • tuples - For details, see tuples in the Search Developer's Guide
  • values - For details, see values in the Search Developer's Guide
  • debug - For details, see debug in the Search Developer's Guide
  • forest - For details, see forest in the Search Developer's Guide
  • quality-weight - For details, see quality-weight in the Search Developer's Guide
  • return-aggregates - For details, see return-aggregates in the Search Developer's Guide
  • return-frequencies - For details, see return-frequencies in the Search Developer's Guide
  • return-metrics - For details, see return-metrics in the Search Developer's Guide
  • return-values - For details, see return-values 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.

Usage Notes

For details and more examples, see Returning Lexicon Values With search:values in the Search Developer's Guide.

Example

xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search"
    at "/MarkLogic/appservices/search/search.xqy";

let $options := 
<options xmlns="http://marklogic.com/appservices/search">
  <values name="uri">
    <uri/>
    <aggregate apply="min"/>
  </values>
</options>
return
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>
    

Example

xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search"
     at "/MarkLogic/appservices/search/search.xqy";

(: 
   Requires URI lexicon and string range index on "hello". 
   This finds the values for "hello" for all documents that 
   have the element "hello".
:)
let $options := 
<options xmlns="http://marklogic.com/appservices/search">
  <tuples name="hello">
    <uri/>
    <range type="xs:string" collation="http://marklogic.com/collation/">
      <element ns="" name="hello"/>
    </range>
  </tuples>
</options>
let $values:= search:values("hello", $options)
return (
$values, 
fn:doc($values/search:tuple/search:distinct-value/fn:data()) )
=>
<values-response name="hello" 
  xmlns="http://marklogic.com/appservices/search" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <tuple frequency="1">
    <distinct-value xsi:type="xs:string" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      >/date.xml</distinct-value>
    <distinct-value xsi:type="xs:string" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      >2012-08-10-05:00</distinct-value>
  </tuple>
  <tuple frequency="1">
    <distinct-value xsi:type="xs:string" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      >/gajanan.xml</distinct-value>
    <distinct-value xsi:type="xs:string" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      >fooooooooo</distinct-value>
  </tuple>
  <metrics>
    <values-resolution-time>PT0.0006S</values-resolution-time>
    <aggregate-resolution-time>PT0.000014S</aggregate-resolution-time>
    <total-time>PT0.002337S</total-time>
  </metrics>
</values-response>
<?xml version="1.0" encoding="UTF-8"?>
<hello>2012-08-10-05:00</hello>
<?xml version="1.0" encoding="UTF-8"?>
<foo>bar</foo>
    

Example

xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search"
    at "/MarkLogic/appservices/search/search.xqy";

let $options := 
<options xmlns="http://marklogic.com/appservices/search">
  <values name="animals">
    <range type="xs:string">
      <field name="animal-name" collation="http://marklogic.com/collation/" />
    </range>
  </values>
</options>
return
search:values("animals", $options, 
  search:parse("mammal OR marsupial", (), "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>
  

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