artifactoryartifactory-query-lang

How to inverse query using Artifactory Query Language?


In Artfactory, I have a list of "repo" properties, some of which come with a "path" property. I need to find all items that do not match these properties. I was wondering if there was a way to structure my logic so that this could be done in one query.

Here's my current, broken logic:

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")'

The issue with this is that while the "repo" property is unique, the "path" property is not. All subdirectories would thus be excluded from the query result.


Solution

  • Yes. AQL is like a logical clause and therefore we can structurize it. I'm assuming the following is the original query:

    {
      "$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 the following query deduced:

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