Max
Max
Explore posts from servers
ATApache TinkerPop
Created by Max on 9/3/2024 in #questions
Gremlin query to order vertices with some locked to specific positions
Thank you! It was useful, I didn't know you could use by modulator for order like this.
17 replies
ATApache TinkerPop
Created by Max on 9/3/2024 in #questions
Gremlin query to order vertices with some locked to specific positions
Here is the sample graph:
g.addV('Category').
property('name', 'Shoes').as('shoes').
addV('Product').
property('name', 'Product1').as('p1').
addE('belongsTo').from('p1').to('shoes').
addV('Product').
property('name', 'Product2').as('p2').
addE('belongsTo').from('p2').to('shoes').
addV('Product').
property('name', 'Product3').as('p3').
addE('belongsTo').from('p3').to('shoes').
addV('Product').
property('name', 'Product4').as('p4').
addE('belongsTo').from('p4').to('shoes').
addV('Product').
property('name', 'Product5').as('p5').
addE('belongsTo').from('p5').to('shoes').
addV('Product').
property('name', 'Product6').as('p6').
addE('belongsTo').from('p6').to('shoes').
addV('Product').
property('name', 'Product7').as('p7').
addE('belongsTo').from('p7').to('shoes').
addV('Product').
property('name', 'Product8').as('p8').
addE('belongsTo').from('p8').to('shoes').
addV('Product').
property('name', 'Product9').as('p9').
addE('belongsTo').from('p9').to('shoes').
property('lockedPosition', 7).
addV('Product').
property('name', 'Product10').as('p10').
addE('belongsTo').from('p10').to('shoes').
property('lockedPosition', 3).
iterate()
g.addV('Category').
property('name', 'Shoes').as('shoes').
addV('Product').
property('name', 'Product1').as('p1').
addE('belongsTo').from('p1').to('shoes').
addV('Product').
property('name', 'Product2').as('p2').
addE('belongsTo').from('p2').to('shoes').
addV('Product').
property('name', 'Product3').as('p3').
addE('belongsTo').from('p3').to('shoes').
addV('Product').
property('name', 'Product4').as('p4').
addE('belongsTo').from('p4').to('shoes').
addV('Product').
property('name', 'Product5').as('p5').
addE('belongsTo').from('p5').to('shoes').
addV('Product').
property('name', 'Product6').as('p6').
addE('belongsTo').from('p6').to('shoes').
addV('Product').
property('name', 'Product7').as('p7').
addE('belongsTo').from('p7').to('shoes').
addV('Product').
property('name', 'Product8').as('p8').
addE('belongsTo').from('p8').to('shoes').
addV('Product').
property('name', 'Product9').as('p9').
addE('belongsTo').from('p9').to('shoes').
property('lockedPosition', 7).
addV('Product').
property('name', 'Product10').as('p10').
addE('belongsTo').from('p10').to('shoes').
property('lockedPosition', 3).
iterate()
Note, the edge Product9 -belongsTo-> shoes has property lockedPosition: 7. The edge Product10 -belongsTo-> shoes has property lockedPosition: 3 . A traversal like g.V().hasLabel("Category").in("belongsTo").values("name") returns products with no specific order. My goal is to create a traversal such that getting products in shoes category would always result in a list, where 3rd and 7th positions would be always occupied by Product10 and Product9 respectively. Alternatively, I am okay with accommodating a different data model for this use case, if it makes for simpler or more efficient traversals.
17 replies