- https://jamesthornton.com#EXIWlRrkjKE
- https://twitter.com/Rangers/status/1641554510605611011
- https://twitter.com/astros/status/1641996751618940936
- https://www.youtube.com/watch?v=S7c3lzpDkvQ#7SlILk2WMTI
- https://gist.github.com/espeed/dd3026536ec3d38afea1072941670f52#3ch6eXkQWU8-C5TDc46E1G4-trIjpVH8h88-UcW056B9jeQ-LvG_M_fAkXU
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: | |
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
import groovy.json.JsonSlurper | |
def slurper = new JsonSlurper() | |
data = slurper.parseText('{"age":34,"name":"James"}') | |
elementIndex = g.idx('people') | |
verticesIndex = g.idx('vertices') | |
g.setMaxBufferSize(0) | |
g.startTransaction() | |
vertex = g.addVertex(data) | |
AutomaticIndexHelper.addElement(elementIndex,vertex) | |
AutomaticIndexHelper.addElement(verticesIndex,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
import groovy.json.JsonSlurper | |
def slurper = new JsonSlurper() | |
keys = null | |
if (keys != null) | |
keys = slurper.parseText(keys) | |
public abstract class People implements Vertex {} | |
index = g.createAutomaticIndex('people',People.class,keys) |
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
outE: | | |
g.v($_id).outE($label) | |
inE: | | |
g.v($_id).inE($label) | |
bothE: | | |
g.v($_id).bothE($label) | |
outV: | |
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
class Vertex(Element): | |
"""A container for Vertex elements returned by the resource.""" | |
def outE(self,label=None): | |
"""Return the outgoing edges of the vertex.""" | |
params = dict(_id=self._id,label=label) | |
script = self._resource.scripts.get('outE',params) | |
return self.gremlin(script) | |
def inE(self,label=None): |
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
import groovy.json.JsonSlurper | |
def slurper = new JsonSlurper() | |
keys = data = null | |
if ('null' != 'null') | |
keys = slurper.parseText('null') | |
if ('{"age":35,"name":"James Thornton"}' != 'null') | |
data = slurper.parseText('{"age":35,"name":"James Thornton"}') | |
vertex = g.getRawGraph().getNodeById(9) | |
manager = g.getRawGraph().index() | |
index = manager.forNodes('test_idxV') |
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
manager = g.getRawGraph().index() | |
index = manager.forNodes(index_name) | |
g.setMaxBufferSize(0) | |
g.startTransaction() | |
vertex = g.getRawGraph().createNode() | |
for (entry in data.entrySet()) { | |
if (entry.value == null) continue; | |
vertex.setProperty(entry.key,entry.value) | |
if (keys == null || keys.contains(entry.key)) | |
index.add(vertex,entry.key,entry.value) |
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
POST url: http://localhost:7474/db/data/ext/GremlinPlugin/graphdb/execute_script | |
POST body: {"params":{"keys":["name"],"index_name":"test_idxV","data":{"age":34,"name":"James Thornton"}},"script":"manager = g.getRawGraph().index()\nindex = manager.forNodes(index_name)\ng.setMaxBufferSize(0)\ng.startTransaction()\nvertex = g.getRawGraph().createNode()\nfor (entry in data.entrySet()) {\n if (entry.value == null) continue;\n vertex.setProperty(entry.key,entry.value)\n if (keys == null || keys.contains(entry.key))\n index.add(vertex,entry.key,entry.value)\n}\ng.stopTransaction(TransactionalGraph.Conclusion.SUCCESS)\nreturn vertex\n"} |
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
def create_indexed_vertex(data,index_name,keys) { | |
manager = g.getRawGraph().index() | |
index = manager.forNodes(index_name) | |
g.setMaxBufferSize(0) | |
g.startTransaction() | |
vertex = g.getRawGraph().createNode() | |
for (entry in data.entrySet()) { | |
if (entry.value == null) continue; | |
vertex.setProperty(entry.key,entry.value) | |
if (keys == null || keys.contains(entry.key)) |
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
try { | |
return create_indexed_vertex(data,index_name,keys) | |
} catch (e) { | |
def create_indexed_vertex(data,index_name,keys) { | |
manager = g.getRawGraph().index() | |
index = manager.forNodes(index_name) | |
g.setMaxBufferSize(0) | |
g.startTransaction() | |
vertex = g.getRawGraph().createNode() | |
for (entry in data.entrySet()) { |