This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function shortestPath(adjList, v, goal) { | |
var visited = [] | |
var queue = []; | |
var shortestDistance = {}; | |
var distance = {} | |
var adjListKeys = Object.keys(adjList); | |
for (var i = 0; i < adjListKeys.length; i++) { | |
var node = adjListKeys[i]; | |
if (node !== v.toString()) { | |
shortestDistance[node] = -1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let $time := xs:dateTime("2015-12-16T17:30:00Z") | |
let $period := cts:period($time) | |
let $query := cts:period-range-query("system","ALN_CONTAINS", $period) | |
return cts:search(/,$query) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cts:element-range-query(xs:QName("xdmp:document"),"=","myUri.xml","collation=http://marklogic.com/collation/codepoint") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "1.0-ml"; | |
declare namespace html = "http://www.w3.org/1999/xhtml"; | |
let $existing := map:entry("foo",9) | |
let $maps := ( | |
map:entry("foo",1), | |
map:entry("foo",2), | |
map:entry("foo",3), | |
map:entry("foo",4), | |
map:entry("foo",5), | |
map:entry("foo",1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import module namespace sec="http://marklogic.com/xdmp/security" at | |
"/MarkLogic/security.xqy"; | |
declare function local:document-get-permissions($uri) { | |
xdmp:document-get-permissions($uri) ! | |
xdmp:invoke-function(function() { | |
element role {., | |
sec:get-role-names(xs:unsignedLong(.//sec:role-id )) | |
} | |
},<options xmlns="xdmp:eval"><database>{xdmp:database("Security")}</database></options>) | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let $test := element outer { | |
attribute at {1}, | |
element a { "a" }, | |
element b { "b" }, | |
element c { "c" } | |
} | |
return | |
element outer { | |
$test/(node()|@*)[. except $test/c] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let $xml := <hi><test><inner>test</inner></test></hi> | |
return $xml/xdmp:unpath("/test/inner") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let $result := element result {"Hi"} | |
return | |
if(fn:contains(xdmp:get-request-header("Accept-encoding"),"gzip")) | |
then | |
( | |
document { | |
xdmp:gzip( | |
text { $result } ) | |
}, | |
xdmp:add-response-header("Content-encoding", "gzip") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare namespace qry = "http://marklogic.com/cts/query"; | |
let $root-element := "*:myRootElem" | |
return | |
cts:term-query(xdmp:plan(/xdmp:unpath($root-element))//qry:final-plan//qry:term-query/qry:key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "1.0-ml"; | |
let $input := for $i in (1 to 100) return $i | |
let $batch-size := 2 | |
let $input-size := fn:count($input) | |
let $num-batches := xs:int(math:ceil($input-size div $batch-size )) | |
let $result := | |
for $batch-start in (1 to $num-batches) | |
let $processing-seq := $input[($batch-size * ($batch-start - 1) + 1) to ($batch-size * ($batch-start ))] | |
return | |
xdmp:spawn-function(function() { |
OlderNewer