Skip to content

Instantly share code, notes, and snippets.

View ableasdale's full-sized avatar

Alex Bleasdale ableasdale

View GitHub Profile
@ableasdale
ableasdale / positions-heavy-near-query.xqy
Created March 29, 2016 18:32
An example of a positions heavy near query
let $q1 := cts:or-query(("0","5"))
let $q2 := cts:or-query(("1","6"))
let $q3 := cts:or-query(("2","7"))
let $q4 := cts:or-query(("3","8"))
let $q5 := cts:or-query(("4","9"))
let $q6 := cts:near-query(($q1,$q2),100)
let $q6 := cts:near-query(($q3,$q3),100)
let $q7 := cts:near-query(($q3,$q4),100)
let $q8 := cts:near-query(($q4,$q5),100)
let $q9 := cts:or-query(($q6,$q7))
@ableasdale
ableasdale / lots-of-positions.xqy
Created March 29, 2016 18:27
Create a test document that is going to require a lot of positions
xdmp:document-insert("1.xml",<a>{for $x in 1 to 10000 return " 0 1 2 3 4 5 6 7 8 9"}</a>)
@ableasdale
ableasdale / posting-positions.xqy
Created March 29, 2016 18:02
MarkLogic: Adding Posting Positions
xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
declare variable $config := admin:get-configuration();
let $config := admin:group-add-trace-event($config, admin:group-get-id($config, "Default"),
(
admin:group-trace-event("Posting Positions 2X")
)
@ableasdale
ableasdale / timestamps.xqy
Created March 24, 2016 17:02
Get Timestamps from the log and get times for them
(: 2016-03-21 19:36:59.684 Notice: Documents: XDMP-OLDSTAMP: Timestamp too old for forest Documents (14582829718819729 < 14584613478666680; 14585890140870470) :)
(14582829718819729, 14584613478666680, 14585890140870470) ! xdmp:timestamp-to-wallclock(.)
@ableasdale
ableasdale / binary-xdmp-plan.xqy
Created March 18, 2016 09:41
Useful xdmp:plan for binary
declare namespace qry = "http://marklogic.com/cts/query"; cts:uris((),(),cts:and-query(xdmp:plan(/binary())//qry:term-query/qry:key ! cts:term-query(.)))
@ableasdale
ableasdale / sar-switches.bat
Created February 29, 2016 11:21
Example SAR switches
sar -uqBrp -n ALL -f 04_sa20
@ableasdale
ableasdale / forest-and-replica-rest.xqy
Last active February 24, 2016 15:16
MarkLogic: ReST API - Create a forest with a replica on another host
xquery version "1.0-ml";
(:
1) setup a cluster with a couple of hosts (127.0.0.1, 127.0.0.2)
2) create forest (replicatest) on host 127.0.0.2
3) create forest (test) on host 127.0.0.1
:)
declare variable $payload-status := '{
"forest-name":"test",
"host":"' || xdmp:hostname() || '",
@ableasdale
ableasdale / jsearch.sjs
Created February 23, 2016 10:30
MarkLogic JSearch example
var jsearch = require('/MarkLogic/jsearch.sjs');
jsearch.documents()
.where( jsearch.byExample({ orderDate: {$ge: "1960-01-01T00:00:00.000"} }) )
.orderBy(cts.indexOrder(cts.jsonPropertyReference('orderDate'), 'ascending'))
.slice(0,10)
.map(function(doc) {return doc.document;})
.withOptions({returnQueryPlay: true})
.result();
@ableasdale
ableasdale / bootstrap-tmpl.xqy
Created February 17, 2016 14:19
MarkLogic Bootstrap Page Template
xquery version "1.0-ml";
declare function local:create-bootstrap-page($title as xs:string, $content as element()){
element html { attribute lang {"en"},
element head {
element meta { attribute charset {"utf-8"}},
element meta { attribute http-equiv {"X-UA-Compatible"}, attribute content {"IE=edge"} },
element meta { attribute name {"viewport"}, attribute content {"width=device-width, initial-scale=1"} },
element title {$title},
element link {
@ableasdale
ableasdale / sample-csv.xqy
Created February 17, 2016 10:13
Sample CSV output
xquery version "1.0-ml";
declare namespace obj="http://marklogic.com/solutions/obi/object";
declare function local:header(){
text {"One,Two"}
};
declare function local:process($uri as xs:string) {
text {fn:string-join((cts:element-values(xs:QName("obj:id"), (), (), cts:document-query($uri)), cts:element-values(xs:QName("obj:type"), (), (), cts:document-query($uri))), ",")}