Hi Erik,
Verified and working fine. Thanks for the quick response.
I tried the same for both string and structured queries and here are the
signatures for the custom functions.
*Structured Query:*
declare function namespace:custom-structured-query(
$query-elem as element(search:custom-constraint-query),
$options as element(search:options)
) as schema-element(cts:query)
{
<root>{
cts:element-value-query(xs:QName("title"),$query-elem/search:text/string(.))
}</root>/*
};
*String Query:*
declare function namespace:custom-string-query(
$query-elem as xs:string,
$right as schema-element(cts:query)
) as schema-element(cts:query)
{
<root>{
cts:element-value-query(xs:QName("title"),$right//cts:text/string(.))
}</root>/*
};
*common for both(string and structured):*
declare function namespace:custom-query(
$query-elem,
$right
) as schema-element(cts:query)
{
<root>{
if($query-elem instance of element(search:custom-constraint-query))
then
cts:element-value-query(xs:QName("title"),$query-elem/search:text/string(.))
else if($query-elem instance of xs:string)
then
cts:element-value-query(xs:QName("title"),$right//cts:text/string(.))
else cts:and-query(())
};}</root>/*
Please suggest the better approach whether to write two separate
constraints and call string and structured queries separately or write
one common method and use "instance of" to use the exact
functionality.
Thanks,
Rajesh
On Mon, Jan 28, 2013 at 4:02 PM, Rajesh Kumar <[email protected]> wrote:
> Hi,
>
>
> As part of our requirement, we need to pass a value using Search REST
> API in Marklogic 6. We are trying to use structuredQuery endpoint to
> achieve this. Please find the sample below:
>
> http://localhost:8006/v1/search?structuredQuery={"query": {"queries":
> {"custom-constraint-query": {"constraint-name": "test","text": ["*Language
> *"]}}}}&options=search
>
> *options node:*
>
> <search:options>
> <search:constraint name="test">
> <search:custom facet="false">
> <search:parse apply="construct-query"
> ns="my-namespace<http://hmhpub.com/orgID>"
> at="/abc.xqy"/>
> </search:custom>
> </search:constraint>
> </search:options>
>
> *abc.xqy:*
>
> declare function construct-query(
> $constraint-qtext as xs:string,
> $right as schema-element(cts:query))
> as schema-element(cts:query)
> {
>
> <root>{cts:element-value-query(xs:QName("title"),$right//cts:text/text())}</root>/*
>
>
> *Exception:*
>
> < rapi:error><rapi:status-code>500</rapi:status-code><rapi:status>INTERNAL
> ERROR</rapi:status><rapi:message-code>XDMP-NONMIXEDCOMPLEXCONT</rapi:message-code><rapi:message>XDMP-NONMIXEDCOMPLEXCONT:
> fn:data(<custom-constraint-query xmlns="
> http://marklogic.com/appservices/search"><constraint-name>test</constraint-name><text>Language</tex...</custom-constraint-query>)
> -- Node has complex type with non-mixed complex content. See the MarkLogic
> server error log for further detail.</rapi:message></rapi:error>
> } ;
>
>
> Thanks,
> Rajesh
>
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general