Skip to content

Instantly share code, notes, and snippets.

View ableasdale's full-sized avatar

Alex Bleasdale ableasdale

View GitHub Profile
@ableasdale
ableasdale / spawn-bulk-delete.xqy
Last active January 11, 2017 13:20
MarkLogic: Simple Example of a bulk delete of documents from a URI query
xquery version "1.0-ml";
declare variable $TARGET-DIRECTORY as xs:string := "/";
declare variable $TARGET-DATABASE as xs:string := "YourDatabaseName";
declare variable $BATCH-SIZE as xs:integer := 20000;
for $uri in cts:uris("", ("document", "limit="||$BATCH-SIZE), cts:directory-query($TARGET-DIRECTORY))
return
xdmp:eval(
"declare variable $URI as xs:string external;
@ableasdale
ableasdale / get-forests-allowed.xqy
Created October 27, 2016 20:13
MarkLogic: Using admin:forest-get-updates-allowed
xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
declare variable $CONFIG := admin:get-configuration();
admin:forest-get-updates-allowed($CONFIG, admin:forest-get-id($CONFIG, "Documents"))
@ableasdale
ableasdale / xdmp-local-save.xqy
Created October 25, 2016 07:39
Saving XML documents to the local filesystem for a support ticket
xquery version "1.0-ml";
declare variable $URIS as xs:string+ := ("/doc1.xml", "/doc2.xml", "/doc3.xml");
for $uri at $pos in $URIS
return xdmp:save("/tmp/" || $pos || ".xml", fn:doc($uri))
@ableasdale
ableasdale / simple-document-move.xqy
Created October 13, 2016 13:07
Simple Document move example
xquery version "1.0-ml";
for $i in cts:uris (
(),
("limit=10000"),
cts:not-query(cts:collection-query("moved"))
)
let $document := fn:doc($i)
return
(xdmp:document-add-collections($i, "moved"),
@ableasdale
ableasdale / LFCS_study
Created October 3, 2016 06:23 — forked from gojun077/LFCS_study
LFCS Study Outline 2015.02.28
* LFCS Domains 2015.02
Note - the domains will change somewhat in March 2015. SW RAID
with mdadm will be removed
** The Command Line
*** Editing text files on the CLI
Covers the use of the basic text editors nano and gedit as well
as the advanced editors _vi_ and _emacs_
- nano
simple CLI-based text editor
@ableasdale
ableasdale / binary-uris.xqy
Created September 23, 2016 12:56
Get binary URIs back from the URI lexicon
xquery version "1.0-ml";
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 / search-relevance-test.xqy
Created September 22, 2016 17:30
Search:Search relevance test
xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";
xdmp:document-insert("/doc1.xml",text{"101 dalmatians is a fun story about dogs escaping from the hands of Cruella"}),
xdmp:document-insert("/doc2.xml",text{"Fun, fun, fun by the Beach Boys"}),
xdmp:document-insert("/doc3.xml",text{"Dogs are fun"}),
xdmp:document-insert("/doc4.xml",text{"Fun"}),
xdmp:document-insert("/doc5.xml",text{"Dogs are fun. Dogs are fun."}),
search:search("fun")
@ableasdale
ableasdale / search-score.xml
Created September 22, 2016 16:02
search:search scoring output example
<search:result index="1" uri="/doc2.xml" path="fn:doc(&quot;/doc2.xml&quot;)" score="3072" confidence="0.2275476" fitness="0.2886751">
<search:snippet>
<search:match path="fn:doc(&quot;/doc2.xml&quot;)/text()"><search:highlight>Fun</search:highlight>, fun, fun by the Beach Boys<search:highlight>fun</search:highlight>, fun by the Beach Boys<search:highlight>fun</search:highlight> by the Beach Boys</search:match>
</search:snippet>
</search:result>
@ableasdale
ableasdale / relevance-trace.xml
Created September 22, 2016 15:54
Relevance Trace Computation Example
<qry:relevance-info xmlns:qry="http://marklogic.com/cts/query">
<qry:score formula="(256*scoreSum/weightSum)+(256*qualityWeight*documentQuality)" computation="(256*12/1)+(256*1*0)">3072</qry:score>
<qry:confidence formula="sqrt(score/(256*8*maxlogtf*maxidf))" computation="sqrt(3072/(256*8*18*log(5)))">0.2275476</qry:confidence>
<qry:fitness formula="sqrt(score/(256*8*maxlogtf*avgidf))" computation="sqrt(3072/(256*8*18*(0/1)))">0.2886751</qry:fitness>
<qry:uri>/doc2.xml</qry:uri>
<qry:path>fn:doc("/doc2.xml")</qry:path>
<qry:term weight="0.125">
<qry:score formula="8*weight*logtf" computation="1*12">12</qry:score>
<qry:key>8828337839282077581</qry:key>
<qry:annotation>word("fun")</qry:annotation>
@ableasdale
ableasdale / search-fragments.xqy
Created September 2, 2016 07:04
Using search:search to resolve at document fragment scope
xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";
search:search("term",
<options xmlns="http://marklogic.com/appservices/search">
<debug>true</debug>
<fragment-scope>properties</fragment-scope>
<sort-order type="xs:string"
collation="http://marklogic.com/collation/"