需要XQuery语法来实现搜索API中的'if Exists()'行为 [英] Need XQuery syntax for 'if Exists()' behaviour in search api
问题描述
我有一个要求,我们仅需要在活动版本中具有<associated-bundles>
元素的文档中执行marklogic搜索.
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.
下面是我们的文档结构
<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>
考虑到上述文档结构,我只需要对有效版本中具有<associated-bundles>
元素的文档执行搜索.
Considering above document structure, I need to perform search only on the documents which have <associated-bundles>
element in their active version.
注意:文档中只有1个活动版本.
Note: There is only 1 active version in the document.
以下是仅在活动文件版本状态"内搜索的查询.但是除此之外,我想在文档中包括<associated-bundles>
的'ifExists'检查.
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.
推荐答案
您可以使用 cts:element-query()使用以下文档中的语法:
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( () ))
这篇关于需要XQuery语法来实现搜索API中的'if Exists()'行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!