在搜索API中需要“if Exists()”行为的XQuery语法(Need XQuery syntax for 'if Exists()' behaviour in search

编程入门 行业动态 更新时间:2024-10-28 10:28:10
在搜索API中需要“if Exists()”行为的XQuery语法(Need XQuery syntax for 'if Exists()' behaviour in search api)

我要求我们只需要在其活动版本中具有<associated-bundles>元素的文档中执行marklogic搜索。

以下是我们的文档结构

<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>元素的文档上进行搜索。

注意:文档中只有一个活动版本。

以下是仅在活动文件“version-status”内搜索的查询。 但除此之外,我还希望为文档添加“ifExists”检查<associated-bundles> 。

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) )));

请让我知道,如何实现这一目标。

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.

最满意答案

您可以使用cts:element-query()使用文档中的以下语法检查元素是否存在:

cts:element-query(xs:QName("my-element"),cts:and-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( () ))

更多推荐

本文发布于:2023-08-04 21:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1422042.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语法   XQuery   Exists   API   api

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!