Skip to content

Instantly share code, notes, and snippets.

View dmcassel's full-sized avatar

David Cassel dmcassel

View GitHub Profile
View original-compliance-map.xqy
declare function gs:doc-compliance-map($uri as xs:string)
{
let $query := cts:document-query($uri)
let $map := map:map()
let $doc := gs:highlight($uri, 'a')
let $header1 :=
for $s in $doc/document/body//(section|subsection)
where fn:contains($s/fn:data(compliance), $TERM1)
return fn:count($s)
View highlight.xqy
declare function gs:highlight($uri, $search)
{
for $x in cts:search(fn:doc(xdmp:url-decode($uri)), $search)
return cts:highlight($x, $search, <b>{$cts:text}</b>)
};
View highlight2.xqy
declare function gs:highlight($uri, $search)
{
cts:highlight(
fn:doc(xdmp:url-decode($uri)),
$search,
<b>{$cts:text}</b>
)
};
View consolidated-compliance-map.xqy
declare function local:doc-compliance-map($uri, $terms)
{
let $map := map:new(
for $term in $terms
return map:entry($term, 0)
)
let $doc := fn:doc($uri)
let $_ :=
for $s in $doc/document/body//(section|subsection)
View indexed-compliance-map.xqy
declare function local:doc-compliance-map($uri, $terms)
{
let $map := map:new(
for $term in $terms
return map:entry($term, 0)
)
let $doc := fn:doc($uri)
let $_ :=
for $value in cts:element-values(xs:QName("compliance"), (), "item-frequency", cts:document-query($uri))
View terms.xml
<compliance>TERM1 TERM2</compliance>
<!-- ... becomes... -->
<compliance>TERM1</compliance>
<compliance>TERM2</compliance>
View ml-facets.html
<ml-facets facet-list="model.facets" selected="model.selected"
select="selectFacet(facet, value)" clear="clearFacet(facet, value)"></ml-facets>
View demo-cat-put.js
app.put('/v1*', function(req, res){
if (req.session.user === undefined) {
res.send(401, 'Unauthorized');
} else if (req.path === '/v1/documents' &&
req.query.uri.match('/users/') &&
req.query.uri.match(new RegExp('/users/[^(' + req.session.user.name + ')]+.json'))) {
// The user is try to PUT to a profile document other than his/her own. Not allowed.
res.send(403, 'Forbidden');
} else {
if (req.path === '/v1/documents' && req.query.uri.match('/users/')) {
View to-json.xqy
xquery version "1.0-ml";
module namespace trns = "http://marklogic.com/transform/to-json";
import module namespace json="http://marklogic.com/xdmp/json" at "/MarkLogic/json/json.xqy";
declare function trns:transform(
$content as map:map,
$context as map:map
) as map:map*
{
View gist:800327120e9abaf0abc4
~/software/mlcp-Hadoop2-1.2-1/bin/mlcp.sh import \
-username admin -password admin -host localhost -port 8031 \
-input_file_path data -transform_module /to-json.xqy \
-transform_namespace "http://marklogic.com/transform/to-json" \
-transform_function transform