Created
March 25, 2013 13:08
-
-
Save sarmbruster/5236984 to your computer and use it in GitHub Desktop.
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
@Grab(group="org.neo4j", module="neo4j-community", version="1.9.M05") | |
import org.neo4j.graphdb.* | |
// make sure we start with empty dir | |
def graphDbDir = "/tmp/neo4j-dummy" | |
new File(graphDbDir).deleteDir() | |
def graphDb = new org.neo4j.kernel.EmbeddedGraphDatabase(graphDbDir) | |
def indexer = graphDb.index().relationshipAutoIndexer | |
indexer.startAutoIndexingProperty("name") | |
indexer.setEnabled(true) | |
def index = indexer.autoIndex | |
def tx = graphDb.beginTx() | |
try { | |
Node target = graphDb.createNode() | |
Relationship rel = graphDb.referenceNode.createRelationshipTo(target, DynamicRelationshipType.withName('RELTYPE')) | |
rel.setProperty("name", "first") | |
assert index.get('name', 'first').size() == 1, "relationship added, index should contain 1 element" | |
rel.delete() | |
assert index.get('name', 'first').size() == 0, "relationship deleted, index should be empty" | |
rel = graphDb.referenceNode.createRelationshipTo(target, DynamicRelationshipType.withName('ANOTHER_RELTYPE')) | |
rel.setProperty("name", "first") | |
assert index.get('name', 'first').size() == 1, "relationship re-added, index should contain 1 element" | |
tx.success() | |
} finally { | |
tx.finish() | |
} | |
assert index.get('name', 'first').size() == 1, "after commit, 1 search result should be available" | |
graphDb.shutdown() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment