Skip to content

Instantly share code, notes, and snippets.

@okram
Created November 11, 2011 17:47
Show Gist options
  • Save okram/1358669 to your computer and use it in GitHub Desktop.
Save okram/1358669 to your computer and use it in GitHub Desktop.
public Iterator<Long> evaluateQuery2(final Long shareId, int level, final Long startDate, final Long endDate) {
final Vertex root = g.idx(T.v)[[share_id: 2l]] >> 1;
int subLevel = Integer.MAX_VALUE;
final Vertex secondRoot = root.out('contains').loop(1) {def x = it.object.getProperty('share_id').equals(shareId); if (x) {subLevel = it.loops}; !x}.next();
if (level == 0) {
return secondRoot.out('contains').loopEmit(1) {true} {true}.
filter {it.getProperty('_startDate') <= startDate && (it.getProperty('_endDate').equals(-1l) || it.getProperty('_endDate') >= endDate)}.share_id
} else {
if (subLevel >= level) {
throw new IllegalArgumentException("The share node with provided id is greater than or equal to the desired level: !" + subLevel + " < " + level);
}
return secondRoot.out('contains').loop(1) {it.loops <= (level - subLevel)}.
filter {it.getProperty('_startDate') <= startDate && (it.getProperty('_endDate').equals(-1l) || it.getProperty('_endDate') >= endDate)}.share_id
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment