This file contains hidden or 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 z = "xdmp:zip"; | |
let $parts := | |
element z:parts { | |
for $uri in cts:uris('/sources/', "document", cts:element-query(xs:QName('UploadDocumentMetadata'),cts:and-query(())))[1 to 100] | |
return (<z:part>{$uri}</z:part>, <z:part>{fn:doc($uri)//UploadedDocumentPath/text()}</z:part>) | |
} | |
let $zip := xdmp:zip-create($parts, ( | |
for $p in $parts/z:part | |
return fn:doc($p) ) |
This file contains hidden or 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
xdmp:document-load("/tmp/docs.zip") | |
; | |
declare namespace z = "xdmp:zip"; | |
for $x in xdmp:zip-manifest(doc("/tmp/docs.zip"))//z:part/text() | |
return | |
xdmp:document-insert($x, xdmp:zip-get(doc("/tmp/docs.zip"), $x)) |
This file contains hidden or 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 function local:get-value($name as xs:string) { | |
(: Make sure the $name is valid :) | |
if (fn:string-length($name) le 0) then () | |
else | |
(: Attempt to retrieve the value from the session variable :) | |
if (xdmp:get-session-field($name)) then | |
text{ "Cached:",xdmp:get-session-field($name)} |
This file contains hidden or 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 dir="http://marklogic.com/xdmp/directory"; | |
declare function local:recursive-file-ls($path, $last-modified as xs:dateTime?) { | |
for $i in xdmp:filesystem-directory($path)/dir:entry | |
let $child-path := $i//dir:pathname/text() | |
let $type := $i//dir:type | |
return | |
if ($type eq "directory") then local:recursive-file-ls($child-path, $last-modified) |
This file contains hidden or 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"; | |
(: Queries Per Second Bucketization | |
: Requires a "last-executed" dateTime range index | |
:) | |
declare function local:qps($duration, $number) { | |
$number div ( $duration div xs:dayTimeDuration('PT1S') ) | |
}; |
This file contains hidden or 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 $uri := '/ext/lib/my-search-lib.xqy' | |
let $filename := "/var/opt/MarkLogic/Temp/my-search-lib.xqy" | |
let $code := xdmp:document-get($filename) | |
(: Uncomment the next line to verify the file is able to be read | |
return $code | |
:) | |
(: Using node-replace instead of insert-document causes all permissions and collections to be maintained. :) | |
return xdmp:node-replace(fn:doc($uri)/text(), text{ $code } ) |
This file contains hidden or 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 $epoch := 1397215825 | |
let $dtd := xs:dayTimeDuration(fn:concat('PT', $epoch, 'S')) | |
let $dt := xs:dateTime("1970-01-01T00:00:00-00:00") + $dtd | |
let $re-epoch := ( $dt - xs:dateTime("1970-01-01T00:00:00-00:00") ) div xs:dayTimeDuration('PT1S') | |
return ($epoch, $dt, $re-epoch) |
This file contains hidden or 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
(: Create sample docs :) | |
xquery version "1.0-ml"; | |
( | |
xdmp:document-insert("/test/zero.xml", <doc><a>1</a><b>1</b><c>1</c><d>1</d></doc>), | |
xdmp:document-insert("/test/one.xml", <doc><a>1</a><b>1</b><c>1</c><d></d></doc>), | |
xdmp:document-insert("/test/two.xml", <doc><a>1</a><b>1</b><c></c><d></d></doc>), | |
xdmp:document-insert("/test/three.xml", <doc><a>1</a><b></b><c></c><d></d></doc>), | |
xdmp:document-insert("/test/four.xml", <doc><a></a><b></b><c></c><d></d></doc>) | |
) | |
; |
This file contains hidden or 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"; | |
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy"; | |
declare namespace db ="http://marklogic.com/xdmp/database"; | |
let $constraint := cts:collection-query("content") | |
let $config := admin:get-configuration() |
This file contains hidden or 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"; | |
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy"; | |
declare namespace db ="http://marklogic.com/xdmp/database"; | |
let $constraint := cts:collection-query("content") | |
let $config := admin:get-configuration() |