【问题标题】:Xquery transform error "Invalid coercion () as document-node()"Xquery 转换错误“无效强制 () 作为文档节点 ()”
【发布时间】:2015-05-04 06:29:56
【问题描述】:

我正在尝试使用 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 -d@"./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(我没有包含上面的代码)。 我想念什么?我哪里错了?你能帮帮我吗?

提前致谢,
普里特维

【问题讨论】:

    标签: xml xquery marklogic


    【解决方案1】:

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

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

    此外,您似乎想要处理完整的文档,而不仅仅是 sn-ps。您可以通过将其添加到您的 REST 搜索选项来获得这些:

    <transform-results apply="raw"/>
    

    【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 是的,我想通了并尝试了同样的方法。安装转换时出现此错误:RESTAPI-INVALIDCONTENT: (err:FOER0000) 无效内容:无效的 add-attr 扩展:在 add-attr 扩展的转换函数中,返回 element()?而不是文档节点()?数据类型; add-attr 要么不是有效模块,要么在 marklogic.com/rest-api/transform/add-attr 中不提供扩展功能(转换)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-08
    • 1970-01-01
    • 2013-08-27
    • 2015-01-06
    相关资源
    最近更新 更多