Skip to content

Instantly share code, notes, and snippets.

View ableasdale's full-sized avatar

Alex Bleasdale ableasdale

View GitHub Profile
@ableasdale
ableasdale / ml-plan.xqy
Created January 16, 2015 08:39
MarkLogic Plan Manager (Incomplete)
xquery version "1.0-ml";
declare variable $path-segment := "E:\plan-docs\";
declare variable $query := xdmp:plan(cts:search(doc(), cts:word-query("test")));
declare variable $query2 := xdmp:plan(cts:search(doc(), cts:word-query(("test", "time", "language", "gas", "police", "politics"))));
declare function local:get-distinct-term-keys($query) as xs:unsignedLong* {
distinct-values($query//xs:unsignedLong(*:key))
};
@ableasdale
ableasdale / squid.xqy
Last active August 29, 2015 14:14
MarkLogic: xdmp:http-get() with Squid
xquery version "1.0-ml";
declare function local:http-get-proxy($proxy as xs:string, $uri as xs:string) {
let $host := tokenize($uri,'/')[3]
let $proxyuri := resolve-uri(substring-after($uri, $host), $proxy)
return
xdmp:http-get($proxyuri,
<options xmlns="xdmp:http">
<headers>
@ableasdale
ableasdale / forest-mem-use.xqy
Created January 30, 2015 15:07
Get total memory usage per forest
xquery version "1.0-ml";
(:
: Get the Forest in-memory usage
:)
declare default element namespace "http://marklogic.com/xdmp/status/forest";
declare variable $path as xs:string := 'C:\Users\Public\Documents\ML_status_only_support_dump_20110118';
@ableasdale
ableasdale / average-forest-size.xqy
Created January 30, 2015 15:17
Average Size of a forest
xquery version "1.0-ml";
(:
: Example: calculate the average size of a forest
:)
declare default element namespace "http://marklogic.com/xdmp/status/forest";
declare variable $path as xs:string := 'C:\Users\Public\Documents\ML_status_only_support_dump_20110118';
@ableasdale
ableasdale / on-disk-sizes.xqy
Created January 30, 2015 15:24
Forest aggregate disk size
xquery version "1.0-ml";
(:
: Example: calculate the on-disk size of each forest
:)
declare default element namespace "http://marklogic.com/xdmp/status/forest";
declare variable $path as xs:string := 'E:\support_qa_60.dmp';
@ableasdale
ableasdale / default.xqy
Last active August 29, 2015 14:16
Basic XSD Viewer
xquery version "1.0-ml";
declare variable $filename := xdmp:get-request-field("file");
declare variable $dir-base as xs:string := "C:\Program Files\MarkLogic\Config\";
declare function local:bootstrap-shim($title, $content){
xdmp:set-response-content-type("text/html; charset=utf-8"),
("<!DOCTYPE html>",
<html lang="en">
<head>
@ableasdale
ableasdale / ratios.xqy
Created March 5, 2015 11:54
Limits, Sizes and Ratios
xquery version "1.0-ml";
declare namespace admin = "http://marklogic.com/xdmp/admin";
declare variable $strings := ( "size", "ratio", "threshold", "max", "min", "limit", "rate", "throttle" );
declare variable $dir-base as xs:string := "C:\Program Files\MarkLogic\Config\";
declare function local:display($it as item()*) {
(
" ******************* ",
@ableasdale
ableasdale / meters-fragments.xqy
Created May 4, 2015 13:20
Meters database fragment report (hourly)
xquery version "1.0-ml";
declare namespace meters = "http://marklogic.com/manage/meters";
declare variable $DATABASE-NAME as xs:string := "Documents";
declare variable $FILENAME as xs:string := "/tmp/fragment-report.csv";
declare variable $QUERY := cts:search(doc(),
cts:and-query((
cts:element-query(fn:QName("http://marklogic.com/manage/meters","database-statuses"), cts:and-query(()) ),
@ableasdale
ableasdale / scheduled-tasks.xqy
Created June 3, 2015 14:44
Get a list of all scheduled tasks (as task paths) from a support dump
xquery version "1.0-ml";
declare namespace db = "http://marklogic.com/xdmp/database";
declare namespace gr = "http://marklogic.com/xdmp/group";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
declare variable $SUPPORT-DUMP-FILEPATH as xs:string := 'E:\support-request-go\support-request-go.txt';
declare variable $support as document-node()* := xdmp:document-get(
@ableasdale
ableasdale / support-dump-scheduled-task-info.xqy
Created June 3, 2015 14:55
Get several elements from a support dump regarding scheduled tasks
xquery version "1.0-ml";
declare namespace db = "http://marklogic.com/xdmp/database";
declare namespace gr = "http://marklogic.com/xdmp/group";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
declare variable $SUPPORT-DUMP-FILEPATH as xs:string := 'E:\support-request-go\support-request-go.txt';
declare variable $support as document-node()* := xdmp:document-get(