title: Gremlin: sorting nodes by weights provided by the client
body: <p>Hello dear gremlin jedi,</p>
  <p>I have a bunch of nodes with different labels in my graph:</p>
  <pre><code>  g.addV(&quot;book&quot;).property(:genre, &quot;horror&quot;).as(&quot;b1&quot;)
     .addV(&quot;book&quot;).property(:genre, &quot;biography&quot;).as(&quot;b2&quot;)
     .addV(&quot;book&quot;).property(:genre, &quot;sci-fi&quot;).as(&quot;b3&quot;)
     .addV(&quot;movie&quot;).property(:genre, &quot;biography&quot;).as(&quot;m1&quot;)
     .addV(&quot;movie&quot;).property(:genre, &quot;sci-fi&quot;).as(&quot;m1&quot;)
     .addV(&quot;movie&quot;).property(:genre, &quot;horror&quot;).as(&quot;m3&quot;).iterate
  </code></pre>
  <p>And I'd like to sort them by the genre property providing weights for each value from the client, something like:</p>
  <pre><code>WEIGHTS = {
    &quot;horror&quot;: 3,
    &quot;biography&quot;: 2,
    &quot;sci-fi&quot;: 1
  }
  </code></pre>
  <p>So the result in this case should be something like
  <code>[b3, m1, b2, m1, b1, m3]</code></p>
  <p>In case if a vertex has a genre not mentioned in the weights it should not cause an error, such vertices may be simply ignored or put in the end of results.</p>
  <p>The weights might change from query to query, so I can't store them in the graph.</p>
  <p>My idea is to use the <code>withSideEffect</code> configuration step to pass the weights to the server and then somehow use it to sort the vertices:</p>
  <pre><code>g.withSideEffect(&quot;weights&quot;, WEIGHTS)
   .V().order().by(__.select(&quot;weights&quot;).select(__.values(:genre)))
   .toList()
  </code></pre>
  <p>But apparently it's a wrong way because it results with an error:</p>
  <p><code>This traversal parent does not support the replacement of local traversals: org.apache.tinkerpop.gremlin.process.traversal.step.map.TraversalSelectStep</code></p>
  <p>What would be the right way to achieve my goal?</p>
  <p>Thank you!</p>
  <p>PS: if it's important, I use my own gremlin language variant written in Ruby, but it's semantics more or less follows semantics of the official python client.</p>