use of org.neo4j.graphdb.index.RelationshipIndex in project neo4j by neo4j.
the class TestLuceneIndex method shouldNotBeAbleToAddNullValuesToRelationshipIndex.
@Test
public void shouldNotBeAbleToAddNullValuesToRelationshipIndex() throws Exception {
// GIVEN
RelationshipIndex index = relationshipIndex(EXACT_CONFIG);
// WHEN single null
try {
index.add(graphDb.createNode().createRelationshipTo(graphDb.createNode(), MyRelTypes.TEST), "key", null);
fail("Should have failed");
} catch (IllegalArgumentException e) {
// THEN Good
}
// WHEN null in array
try {
index.add(graphDb.createNode().createRelationshipTo(graphDb.createNode(), MyRelTypes.TEST), "key", new String[] { "a", null, "c" });
fail("Should have failed");
} catch (IllegalArgumentException e) {
// THEN Good
}
}
use of org.neo4j.graphdb.index.RelationshipIndex in project graphdb by neo4j-attic.
the class RelatedNodesQuestionTest method question5346011.
@Test
public void question5346011() {
GraphDatabaseService service = new EmbeddedGraphDatabase("target/soquestion-test");
Transaction transaction = service.beginTx();
try {
RelationshipIndex index = service.index().forRelationships("exact");
// ...creation of the nodes and relationship
Node node1 = service.createNode();
Node node2 = service.createNode();
String a_uuid = "xyz";
Relationship relationship = node1.createRelationshipTo(node2, DynamicRelationshipType.withName("related"));
index.add(relationship, "uuid", a_uuid);
// query
IndexHits<Relationship> hits = index.get("uuid", a_uuid, node1, node2);
assertEquals(1, hits.size());
transaction.success();
} finally {
transaction.finish();
}
service.shutdown();
}
use of org.neo4j.graphdb.index.RelationshipIndex in project graphdb by neo4j-attic.
the class ImdbExampleTest method setUpDb.
@BeforeClass
public static void setUpDb() {
Neo4jTestCase.deleteFileOrDirectory(new File("target/graphdb"));
graphDb = new EmbeddedGraphDatabase("target/graphdb");
Transaction transaction = graphDb.beginTx();
try {
// START SNIPPET: createIndices
IndexManager index = graphDb.index();
Index<Node> actors = index.forNodes("actors");
Index<Node> movies = index.forNodes("movies");
RelationshipIndex roles = index.forRelationships("roles");
// END SNIPPET: createIndices
// START SNIPPET: createNodes
// Actors
Node reeves = graphDb.createNode();
actors.add(reeves, "name", "Keanu Reeves");
Node bellucci = graphDb.createNode();
actors.add(bellucci, "name", "Monica Bellucci");
// multiple values for a field
actors.add(bellucci, "name", "La Bellucci");
// Movies
Node theMatrix = graphDb.createNode();
movies.add(theMatrix, "title", "The Matrix");
movies.add(theMatrix, "year", 1999);
Node theMatrixReloaded = graphDb.createNode();
movies.add(theMatrixReloaded, "title", "The Matrix Reloaded");
movies.add(theMatrixReloaded, "year", 2003);
Node malena = graphDb.createNode();
movies.add(malena, "title", "Malèna");
movies.add(malena, "year", 2000);
// END SNIPPET: createNodes
reeves.setProperty("name", "Keanu Reeves");
bellucci.setProperty("name", "Monica Bellucci");
theMatrix.setProperty("title", "The Matrix");
theMatrix.setProperty("year", 1999);
theMatrixReloaded.setProperty("title", "The Matrix Reloaded");
theMatrixReloaded.setProperty("year", 2003);
malena.setProperty("title", "Malèna");
malena.setProperty("year", 2000);
// START SNIPPET: createRelationships
// we need a relationship type
DynamicRelationshipType ACTS_IN = DynamicRelationshipType.withName("ACTS_IN");
// create relationships
Relationship role1 = reeves.createRelationshipTo(theMatrix, ACTS_IN);
roles.add(role1, "name", "Neo");
Relationship role2 = reeves.createRelationshipTo(theMatrixReloaded, ACTS_IN);
roles.add(role2, "name", "Neo");
Relationship role3 = bellucci.createRelationshipTo(theMatrixReloaded, ACTS_IN);
roles.add(role3, "name", "Persephone");
Relationship role4 = bellucci.createRelationshipTo(malena, ACTS_IN);
roles.add(role4, "name", "Malèna Scordia");
// END SNIPPET: createRelationships
role1.setProperty("name", "Neo");
role2.setProperty("name", "Neo");
role3.setProperty("name", "Persephone");
role4.setProperty("name", "Malèna Scordia");
transaction.success();
} finally {
transaction.finish();
}
}
use of org.neo4j.graphdb.index.RelationshipIndex in project neo4j-clean-remote-db-addon by jexp.
the class Neo4jDatabaseCleaner method clearIndex.
private void clearIndex(Map<String, Object> result) {
IndexManager indexManager = graph.index();
result.put("node-indexes", Arrays.asList(indexManager.nodeIndexNames()));
result.put("relationship-indexes", Arrays.asList(indexManager.relationshipIndexNames()));
try {
for (String ix : indexManager.nodeIndexNames()) {
final Index<Node> index = indexManager.forNodes(ix);
getMutableIndex(index).delete();
}
for (String ix : indexManager.relationshipIndexNames()) {
final RelationshipIndex index = indexManager.forRelationships(ix);
getMutableIndex(index).delete();
}
} catch (UnsupportedOperationException uoe) {
throw new RuntimeException("Implementation detail assumption failed for cleaning readonly indexes, please make sure that the version of this extension and the Neo4j server align");
}
}
use of org.neo4j.graphdb.index.RelationshipIndex in project neo4j by neo4j.
the class LegacyIndexesUpgradeTest method relationshipIndex.
private RelationshipIndex relationshipIndex(GraphDatabaseService db, String name, Map<String, String> config) {
try (Transaction tx = db.beginTx()) {
RelationshipIndex index = db.index().forRelationships(name, config);
tx.success();
return index;
}
}
Aggregations