Hi, Rajesh:

Great to hear of your success.  The code looks right to me.

Regarding the decision between a single custom constraint that sniffs the input 
and multiple explicit custom constraints, the tradeoffs that come to mind are:

*  No risk of using the wrong constraint for the query with a single custom 
constraint
*  Slightly more efficiency with multiple constraints


But I would expect either approach should be fine.


Erik Hennum
________________________________
From: [email protected] 
[[email protected]] on behalf of Rajesh Kumar 
[[email protected]]
Sent: Tuesday, January 29, 2013 2:49 AM
To: [email protected]
Subject: Re: [MarkLogic Dev General] custom constarint query exception in ML6 
REST API

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]<mailto:[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<http://localhost:8006/v1/search?structuredQuery=%7B%22query>":
 {"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