Hi, Rajesh:

To confirm my previous email, the signature for a custom constraint parser is 
different for string and structured query.  The structured query parameters are:

    $query-elem as element(search:custom-constraint-query),
    $options    as element(search:options)

By the way, I noticed that my previous email had a mistake and should have got 
the string from the search:text element instead of the cts:text element.  The 
corrected line:

    cts:element-value-query(xs:QName("title"),$query-elem/search:text/string(.))


Erik Hennum

Footnote:  If anyone ever needs to support both string and structured queries 
on the same options constraint, you can declare more general types (item() and 
element()) for the parameters and branch on "instance of" tests of the 
parameter values.


________________________________
From: [email protected] 
[[email protected]] on behalf of Erik Hennum 
[[email protected]]
Sent: Monday, January 28, 2013 9:03 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] custom constarint query exception in ML6 
REST API

Hi, Rajesh:

The signature for parsing a custom constraint provided by a structured query 
appears to be different from the signature for parsing a custom constraint 
provided by a string query.

I'll look into whether that's a bug.  In the meantime, I've appended the parser 
that worked for me.


Hoping that's useful,


Erik Hennum

xquery version "1.0-ml";

module namespace custcon = "http://marklogic.com/sample/custcon";;

declare namespace search = "http://marklogic.com/appservices/search";;

declare default function namespace "http://www.w3.org/2005/xpath-functions";;
declare option xdmp:mapping "false";

declare function custcon:construct-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//cts:text/string(.))
}</root>/*
};


________________________________
From: [email protected] 
[[email protected]] on behalf of Rajesh Kumar 
[[email protected]]
Sent: Monday, January 28, 2013 2:32 AM
To: [email protected]
Subject: [MarkLogic Dev General] custom constarint query exception in ML6 REST 
API

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<http://marklogic.com/appservices/search%22%3E%3Cconstraint-name%3Etest%3C/constraint-name%3E%3Ctext%3ELanguage%3C/tex...%3C/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

Reply via email to