Marklogic 在rest扩展中执行xpath时使用XDMP-NONMIXEDCOMPLEXCONT
我正在努力做到以下几点Marklogic 在rest扩展中执行xpath时使用XDMP-NONMIXEDCOMPLEXCONT,marklogic,marklogic-8,Marklogic,Marklogic 8,我正在努力做到以下几点 import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; let $options := <options xmlns="http://marklogic.com/appservices/search"> <additio
import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";
let $options := <options xmlns="http://marklogic.com/appservices/search">
<additional-query>
<cts:collection-query xmlns:cts="http://marklogic.com/cts">
<cts:uri>http://ir.abbvienet.com/content-repo/type/envelope</cts:uri>
</cts:collection-query>
</additional-query>
<constraint name="gene">
<range type="xs:string" facet="true">
<path-index>//Hit[@type='GENE']/@id</path-index>
<facet-option>frequency-order</facet-option>
<facet-option>descending</facet-option>
<facet-option>limit=10</facet-option>
</range>
</constraint>
</options>
return
$options//search:constraint[@name='gene']
导入模块名称空间搜索=”http://marklogic.com/appservices/search“在“/MarkLogic/appservices/search/search.xqy”;
let$options:=
http://ir.abbvienet.com/content-repo/type/envelope
//点击[@type='GENE']/@id
频率顺序
下降的
限值=10
返回
$options//search:constraint[@name='gene']
在查询控制台中执行此操作时,效果良好。。但是当我在REST扩展中执行相同的操作时,我会得到以下错误
<error:xquery-version>1.0-ml</error:xquery-version>
<error:message>Node has complex type with non-mixed complex content</error:message>
<error:format-string>XDMP-NONMIXEDCOMPLEXCONT: fn:data(<constraint name="gene" xmlns="http://marklogic.com/appservices/search"><range type="xs:string" facet="true"><path-index>//Hit[@type='GE...</constraint>) -- Node has complex type with non-mixed complex content</error:format-string>
<error:retryable>false</error:retryable>
<error:expr>fn:data(<constraint name="gene" xmlns="http://marklogic.com/appservices/search"><range type="xs:string" facet="true"><path-index>//Hit[@type='GE...</constraint>)</error:expr>
<error:data/>
<error:stack>
1.0-ml
节点具有复杂类型和非混合复杂内容
XDMP-NONMIXEDCOMPLEXCONT:fn:data(constraint name=“gene”xmlns=)http://marklogic.com/appservices/search“range type=“xs:string”facet=“true”路径索引//Hit[@type='GE…/constraint)--节点具有具有非混合复杂内容的复杂类型
假的
fn:data(constraint name=“gene”xmlns=”http://marklogic.com/appservices/search“range type=“xs:string”facet=“true”路径索引//命中[@type='GE…/constraint)
你知道为什么会这样吗
****EDIT在下面添加了我的REST扩展名*************
module namespace repoTest = "http://marklogic.com/rest-api/resource/repoTest";
import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";
declare default function namespace "http://www.w3.org/2005/xpath-functions";
declare option xdmp:mapping "false";
(: Function responding to GET method - must use local name 'get':)
declare function repoTest:get($context as map:map, $params as map:map) as document-node()*
{
let $out :=
try{
let $options := <options xmlns="http://marklogic.com/appservices/search">
<constraint name="gene">
<range type="xs:string" facet="true">
<path-index>//Hit[@type='GENE']/@id</path-index>
<facet-option>frequency-order</facet-option>
<facet-option>descending</facet-option>
<facet-option>limit=10</facet-option>
</range>
</constraint>
</options>
let $facetContraint := $options//search:constraint[@name='gene']
let $_ := xdmp:log("facetContraint :" || $facetContraint)
return $facetContraint
}catch($ex) {
let $log := xdmp:log("ERROR !!!!!")
let $log := xdmp:log($ex)
return ()
}
return document { $out }
};
(: Function responding to PUT method - must use local name 'put'. :)
declare function repoTest:put($context as map:map, $params as map:map, $input as document-node()*) as document-node()?
{
repoTest:notSupportedMsg($context)
};
(: Func responding to DELETE method - must use local name 'delete'. :)
declare function repoTest:delete($context as map:map,$params as map:map) as document-node()?
{
repoTest:notSupportedMsg($context)
};
(: Function responding to POST method - must use local name 'post'. :)
declare function repoTest:post($context as map:map, $params as map:map,$input as document-node()*) as document-node()*
{
repoTest:notSupportedMsg($context)
};
declare private function repoTest:notSupportedMsg($context as map:map) as document-node()*
{
let $_ := map:put($context, "output-status", (501, "Not Supported HTTP method"))
let $output := json:object()
let $errorResponse := json:object()
let $_ := (
map:put($errorResponse, "statusCode", 501),
map:put($errorResponse, "message", "Not Supported HTTP method")
)
let $dummpy := map:put($output, "errorResponse", $errorResponse )
return document {xdmp:to-json($output)}
};
module namespace repoTest=”http://marklogic.com/rest-api/resource/repoTest";
导入模块命名空间搜索=”http://marklogic.com/appservices/search“在“/MarkLogic/appservices/search/search.xqy”;
声明默认函数名称空间“http://www.w3.org/2005/xpath-functions";
声明选项xdmp:映射为“false”;
(:响应GET方法的函数-必须使用本地名称'GET':)
将函数repoTest:get($context作为map:map,$params作为map:map)声明为document-node()*
{
释放美元:=
试一试{
let$options:=
//点击[@type='GENE']/@id
频率顺序
下降的
限值=10
让$FaceConstraint:=$options//search:constraint[@name='gene']
让$|:=xdmp:log(“facetcontracint:| |$facetcontracint”)
返回$FACETCRAINT
}渔获量(以美元计){
让$log:=xdmp:log(“错误!!!!!!!”)
让$log:=xdmp:log($ex)
返回()
}
返回文档{$out}
};
(:响应PUT方法的函数-必须使用本地名称“PUT”。:)
将函数repoTest:put($context作为map:map,$params作为map:map,$input作为document-node()*)声明为document-node()?
{
repoTest:notSupportedMsg($context)
};
(:Func响应DELETE方法-必须使用本地名称“DELETE”。:)
将函数repoTest:delete($context作为map:map,$params作为map:map)声明为document-node()?
{
repoTest:notSupportedMsg($context)
};
(:响应POST方法的函数-必须使用本地名称“POST”。:)
将函数repoTest:post($context作为map:map,$params作为map:map,$input作为document-node()*)声明为document-node()*
{
repoTest:notSupportedMsg($context)
};
将私有函数repoTest:notSupportedMsg($context as map:map)声明为document-node()*
{
let$979;:=map:put($context,“output status”,(501,“Not Supported HTTP method”))
让$output:=json:object()
让$errorResponse:=json:object()
让$\=(
映射:放置($errorResponse,“statusCode”,501),
map:put($errorResponse,“message”,“不支持HTTP方法”)
)
让$dummpy:=map:put($output,“errorResponse”,$errorResponse)
返回文档{xdmp:to json($output)}
};
我能够解决我的问题,但不明白为什么在Rest扩展中会发生这种情况,而在查询控制台中却不会
在REST扩展中,由于$options的默认名称空间,它失败了,一旦删除它,它就可以工作了
functx:change-element-ns-deep($options, '','')
如果有人能解释一下为什么我的问题代码在查询控制台中工作,但在REST扩展中不工作,那就太好了。我能够解决我的问题,但不理解为什么在REST扩展中发生这种情况,而在查询控制台中却没有 在REST扩展中,由于$options的默认名称空间,它失败了,一旦删除它,它就可以工作了
functx:change-element-ns-deep($options, '','')
如果有人能解释为什么我的问题中的代码在查询控制台中工作,但在REST扩展中不工作,那就太好了,上面的代码不是有效的REST扩展。您能演示一下如何在REST扩展中使用代码吗?我添加了我的REST扩展代码,我所做的只是在扩展代码中返回输出o说说您是如何调用REST扩展的?您是否有可能传入一个
format=json
参数?这可能会触发一些自动转换逻辑,而这可能不是预期的XML,特别是搜索命名空间中的XML?我正在使用curlcurl-u reader:reader调用http://10.239.12.85:8042/LATEST/res上面的代码不是一个有效的REST扩展。您可以演示如何在REST扩展中使用代码吗?我添加了我的REST扩展代码,我所做的只是返回我的扩展代码解码器中的输出。您还说了一些关于如何调用您的REST扩展的代码?您是否有可能在<代码>格式= JSON < /代码> PAR中传递?ameter?这可能会触发一些自动转换逻辑,而这可能不是预期的XML,特别是搜索名称空间中的XML?我使用curlcurl-u reader:reader调用它http://10.239.12.85:8042/LATEST/resources/repoTest
名称空间i