Need XQuery syntax for 'if Exists()' behaviour in search api

北慕城南 提交于 2020-01-16 00:44:47

问题


I have a requirement that we need to perform marklogic search only within the documents which have <associated-bundles> element in it's active version.

Below is our document structure

 <document document-status='active'>
 <file> 
     <version id=1 version-status='active'>
         <file-name/>
         <associated-bundles>
            <bundle doc-id="100082"></bundle>
            <bundle doc-id="100083"></bundle>
            <bundle doc-id="100000"></bundle>
         </associated-bundles>
         ...
         <file-level-visits>3</file-level-visits>
     </version>
     <version id=2 version-status='archived'>
         <file-name/>
         <uploaded-by>
         ...
         <file-level-visits>2</file-level-visits>
     </version>
     <version id=3 version-status='archived'>
         <file-name/>
         <uploaded-by>
         ...
         <file-level-visits>4</file-level-visits>
     </version>
 </file>

Considering above document structure, I need to perform search only on the documents which have <associated-bundles> element in their active version.

Note: There is only 1 active version in the document.

Below is the query to search only within active file "version-status". But in addition to this, I want to include 'ifExists' check of <associated-bundles> for the document.

cts:element-query (xs:QName ("version"),cts:and-query ((cts:element-attribute-value-query(fn:QName("","version"), fn:QName("","version-status"), "active", ("lang=en"), 1)
)));

Please let me know, how to achieve this.


回答1:


You can check for the existence of an element using cts:element-query() using the syntax below from the documentation:

cts:element-query(xs:QName("my-element"),cts:and-query( () ))


来源:https://stackoverflow.com/questions/46076264/need-xquery-syntax-for-if-exists-behaviour-in-search-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!