Search code examples
artifactoryartifactory-query-lang

AQL match strings with multiple slashes


I have records in Artifactory like this:

{
    "path": "amc-sw/pcm33/pcm21/system-pcm33-20221017104012.raucb",
    "type": "file",

Now I want to match all records having pcm21 in the path.

I run this query and it gives me a lot of records

  "files": [
    {
      "aql": {
        "items.find": {
          "repo": "amc-sw",
          "$and": [
            {
              "$and": [
                {
                  "path": {
                    "$match": "*pcm21/*"
                  }
} ] } ] } } } ] }
jf rt search --spec query.json --url=$ARTIFACTORY_URL --user=$ARTIFACTORY_USER --access-token=$ARTIFACTORY_PASS 

Changing the match to this also gives a lot of records

                    "$match": "*/pcm21*"

But this gives me exactly zero records

                    "$match": "*/pcm21/*"

Why can't I use two slashes in the matching?


Solution

  • The reason behind "$match": "*/pcm21/*" returning 0 results derives from the path structure "path": "amc-sw/pcm33/pcm21/system-pcm33-20221017104012.raucb",

    The file system-pcm33-20221017104012.raucb comes right after the deepest folder which is pcm21.

    The match structure with ending forward slash requires an additional directory after the pcm21.

    assuming the path would have been amc-sw/pcm33/pcm21/inner-path/system-pcm33-20221017104012.raucb

    the query would return:

    {
    "results": [
        {
            "repo": "amc-sw",
            "path": "pcm33/pcm21/inner-path",
            "name": "system-pcm33-20221017104012.raucb",
            "type": "file",
            "size": 385,
            "created": "2023-03-30T06:19:30.268Z",
            "created_by": "admin",
            "modified": "2023-03-30T06:19:06.638Z",
            "modified_by": "admin",
            "updated": "2023-03-30T06:19:30.268Z"
        }
    ],
    "range": {
        "start_pos": 0,
        "end_pos": 1,
        "total": 1
    }
    

    }