[MarkLogic Dev General] re:Query By Example
Runstein, Robert E. (Contr) (IS)
Robert.Runstein at ngc.com
Mon Feb 22 10:06:46 PST 2010
Hi Justin,
Sorry for the delay in responding, but I was out of town most of last
week.
Your suggestion below worked for me with one exception. I get
XDMP-INVQUERY unless I add an additional cts:word-query with an empty
cts:text element which should not be allowed according to the current
API docs. I'm using version 4.1-2. Was there a change to the
search:resolve code after that version that would account for this? The
below code is working for me.
let $q := <cts:and-query xmlns:cts="http://marklogic.com/cts">
<cts:element-query>
<cts:element>MyElementName</cts:element>
<cts:word-query><cts:text/></cts:word-query>
<cts:and-query>
<cts:element-attribute-value-query>
<cts:element>MyElementName</cts:element>
<cts:attribute>MyAttributeName</cts:attribute>
<cts:text xml:lang="en">text_to_match</cts:text>
</cts:element-attribute-value-query>
</cts:and-query>
</cts:element-query>
</cts:and-query>
return search:resolve(<q>{$q}</q>/element())
Bob
------------------------------------------------------------------------
-----------------------
Bob,
search:resolve is designed as a complement to search:parse. The latter
gives you an annotated cts:query serialized as XML from a string,
appropriate for passing to search:resolve. If you're using
search:resolve without search:parse, for example constructing your own
cts:query, you'll have to serialize the query as XML first. To serialize
a cts:query you just need to wrap it with an element. I've pasted an
example below.
Justin
xquery version "1.0-ml";
import module namespace search =
"http://marklogic.com/appservices/search"
at "/MarkLogic/appservices/search/search.xqy";
let $q as cts:query := cts:and-query(
(cts:element-query(xs:QName("MyElementName"),
cts:and-query("asdf")))
)
return search:resolve(<q>{$q}</q>/element())
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://xqzone.marklogic.com/pipermail/general/attachments/20100222/8f709a9b/attachment.html
More information about the General
mailing list