Created
November 24, 2011 00:50
-
-
Save espeed/1390375 to your computer and use it in GitHub Desktop.
Gremlin: Create Automatic Index & Create Indexed Vertex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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