Search code examples
artifactoryartifactory-query-lang

Force Artifactory to use numerical comparison when searching?


I am trying to find the latest (or earliest, depending on comparison operator) version of an RPM package (the RPM bit is important). I am using AQL query similar to this one:

items.find( 
   { "$and" : [ 
     { "@rpm.metadata.name": { "$eq": "awesome_package"}}, 
     { "@rpm.metadata.version": { "$gte": "19.300.0.58"}} ] 
   })
   .include("@rpm.metadata.version")
   .sort( { "$asc": [ "name" ]})

As already answered by Artifactory KnowledgeBase, it's impossible to sort on properties, so instead of just sorting on @rpm.metadata.version and taking the first top result by using .limit(1) I must use property condition in the find clause.

It appears though that Artifactory's built-in comparison is purely lexicographic, so for the query above I get the following result:

{
"results" : [ {
  "repo" : "yum-private-local",
  "path" : "some/path",
  "name" : "awesome_package-19.300.0.9-1.noarch.rpm",
  "properties" : [ {
    "key" : "rpm.metadata.version",
    "value" : "19.300.0.9"
  } ]
},{
  "repo" : "yum-private-local",
  "path" : "some/path",
  "name" : "awesome_package-19.300.0.58-0.noarch.rpm",
  "properties" : [ {
    "key" : "rpm.metadata.version",
    "value" : "19.300.0.58"
  } ]
},{
  "repo" : "yum-private-local",
  "path" : "some/path",
  "name" : "awesome_package-19.300.0.59-0.noarch.rpm",
  "properties" : [ {
    "key" : "rpm.metadata.version",
    "value" : "19.300.0.59"
  } ]
} ],
"range" : {
  "start_pos" : 0,
  "end_pos" : 3,
  "total" : 3
}
}

This result includes version 19.300.0.9, which, according to RPM spec, is older than what I am searching for (>= 19.300.0.58) and shouldn't be included in the results, but Artifactory finds it nonetheless, most likely due to its search comparisons being lexicographic.

Also note the ordering of the results, which does appear to use numerical sorting (version "19.300.0.9" comes before "19.300.0.58" and "19.300.0.59").

Question: is it possible to force Artifactory to use numerical (SemVer) comparison in search criteria? If not, is there any other way I can exclude irrelevant versions from the result list?


Solution

  • Although not in lines with what is asked but instead of name sorting if done by the created field would also be helpful.

    created: