警报规则是否可以包含集合查询?

时间:2016-09-28 19:17:10

标签: marklogic marklogic-8

使用基于查询的灵活复制时,是否可以在警报规则中使用集合查询?任何人都有一个如何创建这样一个规则的例子吗?

我们希望将需要提取到副本系统的文档添加到集合中,而不是像单词查询那样依赖基于内容的警报。

2 个答案:

答案 0 :(得分:1)

是的,这应该可以正常工作。我没有一个方便的例子。

答案 1 :(得分: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) 
    
  4. 我将在文档部分中汇总一个主题,并尝试发布更多示例等。现在,必须与项目一起移动。希望这有助于有人在路上。