2015-05-04 26 views
1

我试图将我的搜索结果转换为使用XQuery的某种其他格式。我使用的例子XQuery转换像文档:Xquery转换错误“无效强制()作为文档节点()”

xquery version "1.0-ml"; 
module namespace example = "http://marklogic.com/rest-api/transform/add-attr"; 

import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; 


declare function example:transform(
    $context as map:map, 
    $params as map:map, 
    $content as document-node() 
) as document-node() 
{ 
    let $searchResult := $content 
    let $docs := fn:doc($searchResult/search:result/@uri) 
    return $docs 
}; 

安装改造使用

curl --anyauth --user user:password -X PUT [email protected]"./add-attr.xqy" -H "Content-type: application/xquery" 'http://IP-ADD:port/LATEST/config/transforms/add-attr?trans:name=string\?&trans:value=string\?' 

现在,当我尝试搜索任何字符串变换一样:

http://IP-ADD:port/v1/search?q=xyz&transform=add-attr 

我收到以下错误:

<rapi:error 
xmlns:rapi="http://marklogic.com/rest-api"> 
    <rapi:status-code>500</rapi:status-code> 
    <rapi:status>INTERNAL ERROR</rapi:status> 
    <rapi:message-code>XDMP-AS</rapi:message-code> 
    <rapi:message>XDMP-AS: (err:XPTY0004) $service($context, $service-params, $input) -- Invalid coercion: ("{&amp;quot;root&amp;quot;:{&amp;quot;claim&amp;quot;:[{&amp;quot;type&amp;quot;:&amp;quot;In...", ",") as document-node(). See the MarkLogic server error log for further detail.</rapi:message> 
</rapi:error> 

我试图将每个文档转换为JSON转换函数中的搜索结果(我没有包含上面的代码)。 我错过了什么?我错在哪里?你能帮我解决吗?

由于提前,
大地

回答

4

转换在一次调用中接收整个搜索:响应。这意味着$ searchResult/search:result/@ uri XPath为您提供了一页的URI(可能是十个)。当返回类型只有一个时,您将它们作为一系列文档返回。你需要为它们提供一个包装,以便你只有一个文档。就像:

document { 
    fn:doc($content/search:result/@uri) 
} 

此外,它看起来像你想使用完整的文件,而不仅仅是片段。您可以通过将其添加到您的REST搜索选项来获得这些内容:

<transform-results apply="raw"/> 
+0

中提供扩展功能(变换)脚注:可以直接读取查询结果文档没有如http://docs.marklogic.com/guide/rest-dev/bulk#id_65903中所述的变换 – ehennum

0

错误是由于这样的事实,它实际上是一个文本节点,而不是一个文档节点。如果你想解决这个问题,你应该改变预期的参数类型为元素节点(如element())。

+0

是的,我想通了,并尝试相同。在安装转换时出现此错误: * RESTAPI-INVALIDCONTENT:(err:FOER0000)无效的内容:无效的add-attr扩展名:在add-attr扩展的转换函数中,返回element()?而不是document-node()?数据类型; add-attr或者不是有效的模块,或者不在http://marklogic.com/rest-api/transform/add-attr* –

相关问题