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 function local:fib($n) | |
{ | |
if ($n = 1 or $n = 2) then | |
1 | |
else | |
local:fib($n - 1) + local:fib($n - 2) | |
}; |
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 function local:fib($n, $map) | |
{ | |
if ($n = 1 or $n = 2) then | |
1 | |
else | |
let $n1 := fn:string($n - 1) | |
let $n2 := fn:string($n - 2) | |
let $_ := | |
if (map:get($map, $n1)) then () | |
else |
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"; | |
for $i in (1 to 10000) | |
return | |
xdmp:document-insert( | |
"/" || $i || ".xml", | |
<doc> | |
{ | |
let $lo := xdmp:random(10) | |
let $hi := $lo + xdmp:random(10) |
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 function bucket:parse( | |
$query-elem as element(), | |
$options as element(search:options)) | |
as schema-element(cts:query) | |
{ | |
<root> | |
{ | |
let $bucket := fn:tokenize($query-elem/search:text, "-") | |
return | |
cts:and-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
declare function bucket:start( | |
$constraint as element(search:constraint), | |
$query as cts:query?, | |
$facet-options as xs:string*, | |
$quality-weight as xs:double?, | |
$forests as xs:unsignedLong*) | |
as item()* | |
{ | |
let $buckets := $constraint/search:custom/search:bucket | |
for $bucket in $buckets |
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
{ | |
"com.marklogic.samplestack.domain.Contributor": { | |
"displayName": "JoeUser", | |
"userName": "joe@example.com", | |
"id": "cf99542d-f024-4478-a6dc-7e723a51b040", | |
"location": "San Francisco", | |
"reputation": 50, | |
"voteCount": 3, | |
} | |
} |
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
{ | |
"originalId": "3587258", | |
"title": "Blocking until event", | |
"text": "In a web worker, I'm firing off a postMessage() and need to wait for the result before continuing execution. Is there anyway of blocking until the onMessage event occurs, short of busy waiting plus something like Peterson's Algorithm?", | |
"owner": { | |
"displayName": "Michael", | |
}, | |
"accepted": false, | |
"acceptedAnswerId": null, | |
"answerCount": 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
Transaction transaction = startTransaction(SAMPLESTACK_CONTRIBUTOR); |
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
//QnA Document: Mark the Question as having an accepted answer, note | |
//Answer Id for the accepted answer, and update the last activity date. | |
patchBuilder.replaceValue("/acceptedAnswerId", answerId); | |
patchBuilder.replaceFragment("/accepted", true); | |
patchBuilder.replaceValue("/lastActivityDate", ISO8601Formatter.format(new Date())); | |
//Reputation handling: Loop through all answers to find the currently | |
//and previously accepted answers. Increase reputation by 1 for the | |
//user with the current accepted answer. Decrease reputation by 1 for | |
//the user who previously had the accepted answer (if applicable). |
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
// all or nothing – consistency ftw! | |
try { | |
// Transactional updates | |
transaction.commit(); | |
transaction = null; | |
return acceptedDocument; | |
} finally { | |
if (transaction != null) { transaction.rollback(); }; | |
} |