Skip to content

Instantly share code, notes, and snippets.

@espeed
Created November 24, 2011 00:50
Show Gist options
  • Save espeed/1390375 to your computer and use it in GitHub Desktop.
Save espeed/1390375 to your computer and use it in GitHub Desktop.
Gremlin: Create Automatic Index & Create Indexed Vertex
create_automatic_index: |
import groovy.json.JsonSlurper
def slurper = new JsonSlurper()
keys = $keys
if (keys != null)
keys = slurper.parseText(keys)
public abstract class $domain_class implements Vertex {}
index = g.createAutomaticIndex('ideas',Idea.class,keys)
create_indexed_vertex: |
import groovy.json.JsonSlurper
def slurper = new JsonSlurper()
data = slurper.parseText($data)
domainIndex = g.idx('$index_name')
verticesIndex = g.idx('vertices')
g.setMaxBufferSize(0)
g.startTransaction()
vertex = g.addVertex(data)
AutomaticIndexHelper.addElement(domainIndex,vertex)
AutomaticIndexHelper.addElement(verticesIndex,vertex)
g.stopTransaction(TransactionalGraph.Conclusion.SUCCESS)
return vertex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment