MarkLogic 10 Product Documentation
op:offset

op:offset(
   $plan as map:map,
   $start as item()
) as map:map

Summary

This method returns a subset of the rows in the result set. The start parameter specifies the index in the result set to use as the starting point for the return, followed by the remaining rows up to the number specified by the op:limit method.

A common pattern is to page over a result set by using a op:param placeholder parameter for the start and specifying the starting value in bindings for op:result. This approach reuses the cached query instead of recalculating the query on each request.

Parameters
$plan The Optic Plan. You can either use the XQuery => chaining operator or specify the variable that captures the return value from the previous operation.
$start The index in the result set to use as the starting point.

Example

xquery version "1.0-ml";

import module namespace op="http://marklogic.com/optic"
     at "/MarkLogic/optic.xqy";

let $employees := op:from-view("main", "employees")
let $expenses  := op:from-view("main", "expenses")
let $totalexpenses  := op:col("totalexpenses")
return $employees
   => op:join-inner($expenses, op:on(
                    op:view-col("employees", "EmployeeID"),
                    op:view-col("expenses", "EmployeeID")))
   => op:group-by(op:view-col("employees", "EmployeeID"),
                 ("FirstName", "LastName",
                  op:view-col("expenses", "Category"),
                  op:sum($totalexpenses,
                  op:view-col("expenses", "Amount"))))
   => op:order-by(op:view-col("employees", "EmployeeID"))
   => op:offset(2)
   => op:limit(10)
   => op:result()
  
Powered by MarkLogic Server | Terms of Use | Privacy Policy