我正在尝试查询 MarkLogic 中的文档数据库以找到适合多个参数的任何文档:
这必须是真的
- 作者列表必须包含提供的作者 ID
其中任何一个都必须是真的:
- 列表中的任何一个都
extra-documents
必须有一个date-added
比提供的日期更新的字段 - 文档本身必须有一个
newer-document-date
比提供的日期更新的字段
例如,有人可能会传入一个authorId
of10
和一个dateTime
of2017-01-01T00:00:00
下面是解释为什么应该/不应该返回它们的示例(删除了无关的 XML)
This document should be returned because it has an extra-document with a date-added that is more recent than the provided date, and a matching author.
<metadata>
<extra-documents>
<extra-document>
<date-added>2018-09-11T00:00:00</date-added>
</extra-document>
</extra-documents>
<book-authors>
<book-author>10</book-author>
<book-author>20</book-author>
</book-family-authors>
</metadata>
This document should be returned because it has a newer-document-date greater than the provided date
<metadata>
<extra-documents>
<extra-document>
<date-added>2000-09-11T00:00:00</date-added>
</extra-document>
</extra-documents>
<book-authors>
<book-author>10</book-author>
<book-author>20</book-author>
</book-family-authors>
<newer-document-date>2019-02-03T00:00:00</newer-document-date>
</metadata>
This document should NOT be returned because it is missing the author, even though it fills the date requirement on both the extra-document and the newer-document-date
<metadata>
<extra-documents>
<extra-document>
<date-added>2020-09-05T00:00:00</date-added>
</extra-document>
</extra-documents>
<book-authors>
<book-author>20</book-author>
</book-family-authors>
<newer-document-date>2019-02-03T00:00:00</newer-document-date>
</metadata>
我是新手cts:search
,在弄清楚如何构建这样一个可以搜索特定节点的复杂查询时遇到了麻烦。我想出的最好的是:
cts:search(/*,
cts:and-query ((
cts:search(/*:metadata/*:book-authors/*:book-author, $author-id),
cts:element-query(
fn:QName("http://example.com/collection/book-metadata", "newer-document-date"),
cts:true-query()
), <-- this element-query was an attempt to make sure the field exists on the book, as some books don't have this field
cts:search(/*:metadata,
cts:element-range-query(fn:QName("http://example.com/collection/book-metadata", "newer-document-date"), "<", $date-from)
))
)
)
但是,这似乎无法正常工作,并且尝试添加第三个要求非常困难,以至于我现在只是试图实现前两个。对此的任何帮助表示赞赏。我不确定这是否cts:search
是最好的方法,或者我/*:metadata...
是否正确使用诸如搜索特定字段之类的东西