Search code examples
xquerymarklogic

How can I get an XQuery map of MarkLogic document URIs to lexicon (range index) values in the document?


I'm writing a REST API extension where I need to know the mapping of lexicon values to documents.

Given a lexicon (and backing range index), how can I get a map of of document URIs to lexicon (index) values?


Solution

  • In XQuery, for values of an element, use

    cts:value-tuples(cts-uri-reference(), cts:element-reference("foo"))
    

    For values of a field, use:

    cts:value-tuples(cts-uri-reference(), cts:field-reference("foo"))
    

    See also

    cts:collection-reference, 
    cts:element-attribute-reference, 
    cts:path-reference, 
    cts:geospatial-attribute-pair-reference
    cts:geospatial-element-child-reference
    cts:geospatial-element-pair-reference
    cts:geospatial-element-reference
    cts:geospatial-path-reference
    

    You can get a map on co (or n-way) occurence tuples as well, by providing more arguments to cts:value-tuples().