1

是否可以选择性地协调文档,不仅是根据集合过滤,而且还基于特定文档的价值?

目前,以下是我在 Data Hub 中的收集器插件中的示例代码:

/*
* Collect IDs plugin
*
* @param options - a map containing options. Options are sent from Java
*
* @return - an array of ids or uris
*/
function collect(options) {
// by default we return the URIs in the same collection as the Entity name
return cts.uris(null, null, cts.andQuery([cts.collectionQuery("LoadCollection"),cts.collectionQuery("SourceCollection"), cts.collectionQuery("Entity1")])); 

module.exports = {collect: collect
};

如果我想在过滤器中包含来自文档的特定值(按 ElementID 过滤),我应该添加哪些代码修改以仅使特定文档与此元素过滤器协调一致?

以下是 Entity1 的示例文档:

<envelope xmlns="http://marklogic.com/entity-services">
  <headers/>
  <triples/>
  <instance>
    <Entity1 xmlns="">
      <ElementID>WM</Element1>
      <Color>Red</Color>
      <Shape>Circle</Shape>
      <Size>Small</Size>
      <Location></Location>
   </Entity1>
  <attachments/>

4

2 回答 2

2

你需要cts.elementValueQuery

cts.uris(null, null, cts.andQuery([cts.elementValueQuery(xs.QName("ElementId"), "WM"), cts.collectionQuery("LoadCollection"), cts.collectionQuery("SourceCollection"), cts.collectionQuery("Entity1")]));
于 2018-08-01T12:49:50.050 回答
0

您可以简单地修改您的collector.xqy代码如下 -

let $uris := cts:search(doc()/*:envelope/*:instance/*:Entity1,
               cts:and-query((
                 cts:element-value-query(xs:QName("ElementID"),"WM","exact"),      
                 cts:collection-query(("YourCollectionName"))
               )) )
for $i in $uris
    return fn:base-uri($i) 

请注意,我已经编写了此代码,XQuery但您collector.xqyJavaScript.

根据我的理解,您也可以XQuery根据您的要求使用代码,只需进行少量修改。

于 2018-08-01T07:25:34.077 回答