簡體   English   中英

將多個 MarkLogic 查詢與 cts:search 結合使用

[英]Combining multiple MarkLogic queries with cts:search

我正在嘗試在 MarkLogic 中查詢文檔數據庫以找到適合多個參數的任何文檔:

這一定是真的

  1. 作者列表必須包含提供的作者 ID

其中一個必須是真的:

  1. extra-documents列表必須在其中任何一個比提供的日期更新extra-documents date-added字段
  2. 文檔本身必須具有比提供的日期更近的newer-document-date字段

例如,有人可能傳入10authorId2017-01-01T00:00:00dateTime

下面是解釋為什么應該/不應該返回它們的示例(刪除了無關的 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: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...類的東西來搜索特定字段

包裝兩個查詢以查找date-added元素或newer-document-date ,其值小於cts:or-query()$date-from ,並將其應用到cts:and-query()以及$author-id值的cts:element-value-query()

declare namespace meta = "http://example.com/collection/book-metadata";
cts:search(doc(),
  cts:and-query((
    cts:element-value-query(xs:QName("meta:book-author"), $author-id),
    cts:or-query((
      cts:element-query(xs:QName("meta:date-added"), cts:true-query()),
      cts:element-range-query(xs:QName("meta:newer-document-date"), "<", "$date-from")
    ))
  ))
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM