Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: a4717bb0fc
Fetching contributors…

Cannot retrieve contributors at this time

66 lines (51 sloc) 1.926 kB
(:
Copyright 2011 MarkLogic Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
:)
xquery version "1.0-ml";
import module namespace common="http://marklogic.com/mljson/common" at "lib/common.xqy";
import module namespace json="http://marklogic.com/json" at "lib/json.xqy";
declare option xdmp:mapping "false";
let $index := xdmp:get-request-field("__MLJSONURL__:index")
let $index :=
if($index castable as xs:integer)
then xs:integer($index)
else 1
let $start := xdmp:get-request-field("__MLJSONURL__:start")
let $start :=
if($start castable as xs:integer)
then xs:integer($start)
else $index
let $end := xdmp:get-request-field("__MLJSONURL__:end")
let $end :=
if($end castable as xs:integer)
then xs:integer($end)
else $start
let $query := cts:and-query(
for $key in xdmp:get-request-field-names()
where not(starts-with($key, "__MLJSONURL__:"))
return cts:element-value-query(xs:QName(json:escapeNCName($key)), xdmp:get-request-field($key))
)
let $results :=
if(exists($start) and exists($end) and $end > $start)
then cts:search(/json, $query)[$start to $end]
else if(exists($start))
then cts:search(/json, $query)[$start]
else ()
let $total :=
if(exists($results[1]))
then cts:remainder($results[1]) + $start - 1
else 0
let $end :=
if($end > $total)
then $total
else $end
return common:outputMultipleDocs($results, $start, $end, $total)
Jump to Line
Something went wrong with that request. Please try again.