[MarkLogic Dev General] Nested cts:search() functions over JSON documents

Nick Ardlie nick.ardlie at gmail.com
Thu Mar 12 22:34:18 PDT 2015


Is it possible to define nested (i.e. path constrained) queries in
cts:search() over JSON document types in MarkLogic 8?

With XML document types I can nest cts:element-query() functions to achieve
this.
But I don't seem to be able to use the cts:element-query() function for
JSON.
Unless I'm missing something? It requires an xs:QName() parameter and a
local-name only version of a QName doesn't seem to work for JSON documents.

To describe with an example, say I have the following documents (one XML,
the other JSON):

let $xml-doc :=
<doc>
<foo>
<bar>UP HERE</bar>
</foo>
<baz>
<foo>
<bar>DOWN HERE</bar>
</foo>
</baz>
</doc>

let $json-doc := xdmp:unquote(
'{
"foo": {
"bar": "UP HERE"
},
"baz": {
"foo": {
"bar": "DOWN HERE"
}
}
}')

let $insert-result := (xdmp:document-insert("ID-1", $json-doc),
xdmp:document-insert("ID-2", $xml-doc))


With the XML document I can search for foo/bar elements that contain the
word "here" like this:
return cts:search(doc(), cts:element-query(xs:QName("foo"),
cts:element-query(xs:QName("bar"), "here")))

After the above insert this will match the XML document but not the JSON
document.
I'd like to do the equivalent with the JSON document but the similar cts
functions for JSON don't appear to support cts:query nesting (e.g.
cts:json-property-value-query()).
Is there a way to do this with JSON documents?
I know I can constrain the first expression argument to cts:search with an
XPath.
But I'm interested to know if I can achieve this entirely within cts:query
constructs/functions.

Regards,
Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20150313/cb442f47/attachment.html 


More information about the General mailing list