You could break your version number string down into 3 separate attributes (major, minor, point) and keep each of those as an integer.
Consider the following data
create (n:Node {name: 'first',version: '1.2.0', ver_major: 1, ver_minor: 2, ver_point: 0})
create (n:Node {name: 'second',version: '1.10.0', ver_major: 1, ver_minor: 10, ver_point: 0})
As you have see if you search for and order by version they are returned in alphabetical order.
match (n:Node)
return n.name, n.version
order by n.version
One alternative would be to persist the version numbers in separate attributes as integers.
match (n:Node)
return n.name, n.version
order by n.ver_major, n.ver_minor, n.ver_point
Another alternative would be to split the string into component versions and order on those. toInt
is required though otherwise the values will still be ordered as strings.
match (n:Node)
return n.name
, n.version
, toInt(split(n.version,'.')[0]) as major
, toInt(split(n.version,'.')[1]) as minor
, toInt(split(n.version,'.')[2]) as point
order by major, minor, point