【问题标题】:How to inverse query using Artifactory Query Language?如何使用 Artifactory 查询语言进行逆查询?
【发布时间】:2021-09-20 20:51:41
【问题描述】:

在 Artfactory 中,我有一个“repo”属性列表,其中一些带有“path”属性。我需要找到与这些属性不匹配的所有项目。我想知道是否有一种方法可以构建我的逻辑,以便可以在一个查询中完成。

这是我当前的错误逻辑:

curl -u $credentials \
-X POST https://my-artifactory-server.com/artifactory/api/search/aql \
-H content-type:text/plain -d 'items.find({ 
    "$and": [
        {"repo" : {"$neq" : "top_level_directory"}},
        { 
            "$and": [ 
                {"repo" : {"$neq" : "other_top_level_directory"}},
                {"path" : {"$nmatch" : "sub_directory/*"}}
            ]
        }
    ]
}).include("repo","path","name","size","modified")'

问题在于,虽然“repo”属性是唯一的,但“path”属性却不是。因此,所有子目录都将从查询结果中排除。

【问题讨论】:

  • 可以使用德摩根定律进行反转。但是,尚不清楚您想要实现什么。请严格说明您想在查询中找到什么以及您要反转的原始查询是什么?
  • 我想反转一个查询,以查找 Artifactory 中具有“repo”属性“top_level_directory”或“repo”属性“other_top_level_directory”和“path”属性“sub_directory/”的所有项目*”。这可能看起来像这样:or { repo == "top_level_directory", and { repo == "other_top_level_directory", path == "sub_directory/*" } } 我正在寻找的是此查询未找到的每个项目。据我所知,Artifactory 没有 NOT 或 NOR 逻辑,这让事情变得更加困难。

标签: artifactory artifactory-query-lang


【解决方案1】:

是的。 AQL 就像一个逻辑子句,因此我们可以对其进行结构化。 我假设以下是原始查询:

{
  "$or": [
    { "repo": { "$eq": "top_level_directory" } },
    {
      "$and": [
        { "repo": { "$eq": "other_top_level_directory" } },
        { "path": { "$match": "sub_directory/*" } }
      ]
    }
  ]
}
A - repo == top_level_directory
B - repo == other_top_level_directory
C - path =~ sub_directory/*
Original query:
A ∨ (B ∧ C)

Inversion:
¬(A ∨ (B ∧ C))
<=> (De Morgan)
¬A ∧ ¬(B ∧ C))
<=> (De Morgan)
¬A ∧ (¬B ∨ ¬C)) 

并推导出以下查询:

{
  "$and": [
    { "repo": { "$neq": "top_level_directory" } },
    {
      "$or": [
        { "repo": { "$neq": "other_top_level_directory" } },
        { "path": { "$nmatch": "sub_directory/*" } }
      ]
    }
  ]
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多