Hi Nick,
I think you are looking cts:json-property-scope-query:
xquery version "1.0-ml";
let $json-doc := xdmp:unquote(
'{
"foo": {
"bar": "UP HERE"
},
"baz": {
"foo": {
"bar": "DOWN HERE"
}
}
}')
return xdmp:document-insert("/doc.json", $json-doc)
;
"element search",
cts:search(doc(), cts:element-query(xs:QName("foo"),
cts:element-query(xs:QName("bar"), "here"))),
"json search",
cts:search(doc(), cts:json-property-scope-query("foo",
cts:json-property-scope-query("bar", "here")))
Cheers,
Geert
From: Nick Ardlie <[email protected]<mailto:[email protected]>>
Reply-To: MarkLogic Developer Discussion
<[email protected]<mailto:[email protected]>>
Date: Friday, March 13, 2015 at 6:34 AM
To: "[email protected]<mailto:[email protected]>"
<[email protected]<mailto:[email protected]>>
Subject: [MarkLogic Dev General] Nested cts:search() functions over JSON
documents
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
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general