2016-09-28 62 views
2

使用基於查詢的靈活複製時,是否可以在警報規則中使用集合查詢?如果可能的話,任何人都有如何創建這樣的規則的例子?警報規則是否可以包含集合查詢?

我們希望將需要拉到副本系統的文檔添加到集合中,而不是像單詞查詢那樣依賴基於內容的警報。

回答

0

爲了有一個更完整的答案,這裏是我所學到的......從文檔中不是很明顯(至少對我來說)。在使用API​​創建規則與使用XQuery庫之間,我迷失了方向。我發現最適合我的目的不用擔心使用API​​。此示例旨在設置基於查詢的靈活複製時專門使用alert庫。

  1. 設置提醒的CPF域:

    xquery version "1.0-ml"; 
    import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
        at "/MarkLogic/flexrep.xqy"; 
    
    import module namespace alert = "http://marklogic.com/xdmp/alert" 
        at "/MarkLogic/alert.xqy"; 
    (: Run against the content database :) 
    
    let $domain-id := 12956765056276017188 (: There are functions to help get this programmatically :) 
    let $alerting-uri := flexrep:domain-alerting-uri($domain-id) 
    let $existing := alert:config-get($alerting-uri) 
    return 
        if ($existing) 
        then $alerting-uri 
        else 
         (alert:config-insert(
          alert:make-config(
          $alerting-uri, 
          "qbfr", 
          "alerting rules for QBFR", 
          <alert:options/> 
          ) 
         ), fn:concat("Alerting configuration created- ",$alerting-uri)) 
    
  2. 創建警報配置

    xquery version "1.0-ml"; 
    import module namespace alert = "http://marklogic.com/xdmp/alert" 
        at "/MarkLogic/alert.xqy"; 
    (: Run against the content database :) 
    
    let $alerting-uri := 
        "http://marklogic.com/xdmp/flexrep/12956765056276017188/alerting" 
    return 
        alert:action-insert($alerting-uri, alert:make-log-action()) 
    
  3. 插入爲目標用戶規則的日誌動作

    xquery version "1.0-ml"; 
    import module namespace alert = "http://marklogic.com/xdmp/alert" 
        at "/MarkLogic/alert.xqy"; 
    
    let $alerting-uri := "http://marklogic.com/xdmp/flexrep/12956765056276017188/alerting" 
    let $rule-name := "StackFlow-Collection-Alert-Rule" 
    let $description := "Will alert on documents in the StackFlow collection" 
    let $user-id := xdmp:user("my-username") 
    (: The cts query in the rule can use any of the cts constructs! :) 
    let $rule := 
        alert:make-rule(
         $rule-name, 
         $description, 
         $user-id, 
         cts:collection-query("StackFlow"), 
         "log", 
         <alert:options /> 
        ) 
    return 
        alert:rule-insert($alerting-uri, $rule) 
    

我在文檔部分將這個主題放在一起,並會嘗試發佈一些更多的例子等。現在,隨着這個項目一起移動。希望這可以幫助那些在路上的人。

1

是的,這應該很好。我沒有一個方便的例子。

+0

謝謝,我會繼續爲此制定規則... –

相關問題