1
votes

Is it possible to selectively harmonize documents not just filtered on collections but also based on a specific document's value?

Currently, below is the sample code in my collector plugin in 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
};

If I want to include in the filter a specific value from a document (filter by ElementID), what code modification should I add to only harmonize specific documents with this element filter?

Below is a sample document for 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/>

2

2 Answers

2
votes

You need cts.elementValueQuery :

cts.uris(null, null, cts.andQuery([cts.elementValueQuery(xs.QName("ElementId"), "WM"), cts.collectionQuery("LoadCollection"), cts.collectionQuery("SourceCollection"), cts.collectionQuery("Entity1")]));
0
votes

You can simply modify your collector.xqycode as below-

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) 

Please note I have written this code in XQuery but your collector.xqy looks in JavaScript.

As per my understanding you can use XQuery code as well with few modifictaions as per your requirement.