Search in sources :

Example 26 with RelationshipIndex

use of org.neo4j.graphdb.index.RelationshipIndex in project neo4j by neo4j.

the class TestLuceneIndex method testNodeLocalRelationshipIndex.

@Test
public void testNodeLocalRelationshipIndex() {
    RelationshipIndex index = relationshipIndex(LuceneIndexImplementation.EXACT_CONFIG);
    RelationshipType type = withName("YO");
    Node startNode = graphDb.createNode();
    Node endNode1 = graphDb.createNode();
    Node endNode2 = graphDb.createNode();
    Relationship rel1 = startNode.createRelationshipTo(endNode1, type);
    Relationship rel2 = startNode.createRelationshipTo(endNode2, type);
    index.add(rel1, "name", "something");
    index.add(rel2, "name", "something");
    for (int i = 0; i < 2; i++) {
        assertThat(index.query("name:something"), Contains.contains(rel1, rel2));
        assertThat(index.query("name:something", null, endNode1), Contains.contains(rel1));
        assertThat(index.query("name:something", startNode, endNode2), Contains.contains(rel2));
        assertThat(index.query(null, startNode, endNode1), Contains.contains(rel1));
        assertThat(index.get("name", "something", null, endNode1), Contains.contains(rel1));
        assertThat(index.get("name", "something", startNode, endNode2), Contains.contains(rel2));
        assertThat(index.get(null, null, startNode, endNode1), Contains.contains(rel1));
        restartTx();
    }
    rel2.delete();
    rel1.delete();
    startNode.delete();
    endNode1.delete();
    endNode2.delete();
    index.delete();
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipType(org.neo4j.graphdb.RelationshipType) RelationshipIndex(org.neo4j.graphdb.index.RelationshipIndex) Test(org.junit.Test)

Aggregations

RelationshipIndex (org.neo4j.graphdb.index.RelationshipIndex)26 Relationship (org.neo4j.graphdb.Relationship)18 Test (org.junit.Test)13 Node (org.neo4j.graphdb.Node)13 RemoteException (android.os.RemoteException)7 Transaction (org.neo4j.graphdb.Transaction)7 InvalidTransactionException (org.neo4j.javax.transaction.InvalidTransactionException)7 SystemException (org.neo4j.javax.transaction.SystemException)7 ParcelableRelationship (org.neo4j.android.common.ParcelableRelationship)6 RelationshipType (org.neo4j.graphdb.RelationshipType)3 IndexManager (org.neo4j.graphdb.index.IndexManager)3 DynamicRelationshipType (org.neo4j.graphdb.DynamicRelationshipType)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 BeforeClass (org.junit.BeforeClass)1 LuceneTimeline (org.neo4j.index.lucene.LuceneTimeline)1 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)1 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)1