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?]
) as element(search:values-response)

Summary

This function returns lexicon values and allows you to calculate aggregates based on the lexicon values.

Parameters
$spec-name The name of a specification in the supplied options node (a <values> or <tuples> specification).
$options Options to define the search grammar and control the search. See description for $options for the function search:search Must include the $spec-name definitions supplied in the first parameter.

The following is sample options node that includes lexicon specifications:

<options xmlns="http://marklogic.com/appservices/search">
     
    <values name="example">
        <range type="xs:integer">
            <element ns="" name="game"/>
            <attribute ns="" name="runs"/>
        </range>
        <aggregate apply="sum"/>
    </values>

    <!-- uri lexicon -->
    <values name="uri">
      <uri/>
      <values-option>limit=10</values-option>
    </values>  

     <!-- collection lexicon -->
    <values name="coll">
      <collection/>
      <values-option>limit=10</values-option>
    </values>
 
    <!-- user-supplied aggregate -->
    <values name="udf">
        <range type="xs:double">
            <element ns="" name="test"/>
        </range>
        <aggregate apply="mycalc" udf="sampleplugin"/>
    </values>
 
    <!-- co-occurrences -->
    <tuples name="editor-author">
        <range type="xs:string" collation="http://marklogic.com/collation/">
            <element name="editor" ns=""/>
        </range>
        <range type="xs:string" collation="http://marklogic.com/collation/">
            <element name="author" ns=""/>
        </range>
        <lexicon-option>limit=10</lexicon-option>
    </tuples>

    <!-- path -->
    <values name="datepath">
      <range type="xs:dateTime">
        <facet-option>descending</facet-option>
        <facet-option>limit=10</facet-option>
        <path-index 
          xmlns:d="http://purl.org/dc/elements/1.1/"
          >/document/d:date</path-index>
       </range>
    </values>

    <!-- field -->
    <values name="field-range">
        <range type="xs:dateTime">
            <field name="range"/>
        </range>
    </values>
 
    <return-frequency>false</return-frequency>
    <return-values>true</return-values>
    <return-aggregates>true</return-aggregates>
</options> 
$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 not supplied, the values are returned starting with the first value in the range index.

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>

    

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