MarkLogic server side API, Javascript, cts.search, search only in specific nodes -


in marklogic xquery server side api there possibility run cts.search method in following manner:

  cts:search(//speech,     cts:word-query("with flowers"))    => ... sequence of 'speech' element ancestors (or self)      of node containing phrase 'with flowers'. 

my question is, possible achieve such result using javascript api? namely, able run word-query on specific root-level nodes (as database hosts couple of different document types).

(as nodes mentioned root nodes, using elementwordquery not seem handy way achieve goal).

in javascript version of cts.search there no expression parameter xquery api. search words within specific element , text descendants, can use cts.elementwordquery. example,

var resultsiterator = cts.search(cts.elementwordquery(xs.qname('speech'), 'with flowers')); for(var doc of resultsiterator) {   // … } 

this iterates through each of documents. contained speech element, use doc.xpath('//speech') in for…of loop.

rather relying solely on root element document type identifier, i’d recommend using collections manage groups of typed documents. true if you’re managing json documents, typically don’t have notion of “root element”.

var resultsiterator = cts.search(cts.andquery([   cts.collectionquery('speeches'),   cts.wordquery('with flowers') ])); for(var doc of resultsiterator) {   // … } 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -