有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

ApplyTransfermListener。Marklogic Java客户端Api中的ApplyResult?

似乎ApplyTransferMLListener方法withApplyResult有两个值(即REPLACEIGNORE),如documentation中所述。定义如下Whether to REPLACE each document with the result of the transform, or run the transform with each document as input, but IGNORE the result.

我的代码,它实际上做的是从marklogic db获取内容,并应用转换模块。下面我提到了ApplyTransformListener片段:

 ServerTransform transform = new ServerTransform("rest");
            ApplyTransformListener transformListener = new ApplyTransformListener()
              .withTransform(transform)
              .withApplyResult(ApplyResult.REPLACE)

我的转换模块(即rest)是这样的

function patt(context, params, content)
{ 
  var transformed = {};
  transformed.Update= {"New" : "Element"};
  transformed.Original= content;
  xdmp.nodeReplace(content, transformed);
};
exports.transform = patt;

通过使用上面的代码,转换模块将获得内容并应用xdmp.nodeReplace(content, transformed)

我的问题是:

甚至我在applyresult中也这样应用了IGNORE

ServerTransform transform = new ServerTransform("rest");
                ApplyTransformListener transformListener = new ApplyTransformListener()
                  .withTransform(transform)
                  .withApplyResult(ApplyResult.IGNORE)

但它仍在应用变换模块的变化。为什么

它必须忽略转换模块的结果(即,文档中的原始数据不应正确更改)

如果我错了,请纠正我

谢谢


共 (1) 个答案

  1. # 1 楼答案

    当您调用xdmp.nodeReplace时,您正在更改文档,我们不会阻止您这样做。IGNORE选项适用于这样的场景,您希望控制自己的修改,甚至是对其他文档的修改

    使用REPLACE转换函数将返回要替换文档注释的新文档。看这个example from the guide