UPDATE 1
I've added the descLength
and imageLength
properties to allow for easier sorting. The idea is that constant(0)
can be used to fill in the values for users who lack either property, and any length greater than 0 can be used to identify a user who actually has the property. The furthest this gets me is being able to order().by()
only one property at a time, using a query such as:
g.V().
order().
by(coalesce(values('descLength'), constant(0)))
But this isn't the full solution to match what I need.
Original Post
In amazon neptune I want to sort vertices based on the presence of 2 properties, desc
and image
. The order of ranking should be:
- vertices that have both properties
- vertices that have
desc
but notimage
- vertices that have
image
but notdesc
- vertices that have neither property
Consider this graph of users and their properties:
g.addV('user').property('type','person').as('u1').
addV('user').property('type','person').property('desc', 'second person').property('descLength', 13).as('u2').
addV('user').property('type','person').property('desc', 'third person').property('descLength', 12).property('image', 'https://www.example.com/image-3.jpeg').property('imageLength', 36).as('u3').
addV('user').property('type','person').property('image', 'https://www.example.com/image-4.jpeg').property('imageLength', 36).as('u4')
Using the ranking order I outlined, the results should be:
u3
because it has bothdesc
andimage
u2
because it hasdesc
but notimage
u4
because it hasimage
but notdesc
u1
because it has neitherdesc
norimage
The order().by()
samples I've seen work with data like numbers and dates that can be ranked by increasing/decreasing values, but of course strings like urls and text can't. What's the correct way to achieve this?