Sorry if something like this has been answered elsewhere (hard to know what to search on).
I have a pretty simple traversal (albeit with a slightly messy projection step) that looks something like this:
g.V(root).out().order().by(id).range(1000,2000).project("v","e").....) // project step omitted for brevity
As you can see, it uses range for returning paged results. However, on the first results page only, I need to return the total vertex count of the graph too. I've got this working using something like:
g.V(root).out().union(identity().count(), identity().order().by(id).range(0,1000).project("v","e").......)
This works fine for my needs. I've been able to translate this to c#/gremlin.net and successfully run and parsed the results.
The problem is there a chunk of duplicated code in doing so, namely the order and projection step that I need on both versions of the query but in different places.
Given that I have the 'core' part of the traversal, effectively:
I only know how to implement it somelthing like:
.Union<object>(__.Identity().Count(), __.Identity()
.Order().By(__.Id()).Range<GVertex>(Scope.Global, low, high)
.Project<object>("projectedV", "projectedE")
// etc.
else
coreT.
.Order().By(__.Id()).Range<GVertex>(Scope.Global, low, high)
.Project<object>("projectedV", "projectedE")
// etc.
I know I can create the .Order()....Project()... part as an anonymous traversal:
__.Order().By(__.Id()).Range<GVertex>(Scope.Global, low, high)
.Project<object>("projectedV", "projectedE")
Question is, can I append this to the existing 'core' traversal as if I had added it using fluent syntax? I want to be able able to reduce my code to something (VERY ROUGHLY!) like:
if (page==1)
vertexTraversal.Union<object>(__.Identity().Count(), __.Identity() + suffix)
else
vertexTraversal .= suffix
Is this even possible?
I appreciate that some people will try to suggest an alternative solution to my paging solution, and while help is always appreciated, I would like to improve my understanding of gremlin.net by finding out if appending/merginf traversals is possible.