Package org.neo4j.graphdb.index

Examples of org.neo4j.graphdb.index.RelationshipIndex


            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");
        }
View Full Code Here


            org.neo4j.graphdb.index.Index<Node> nodeIndex = this.rawGraph.index().forNodes(indexName);
            if (nodeIndex.isWriteable()) {
                nodeIndex.delete();
            }
        } else if (this.rawGraph.index().existsForRelationships(indexName)) {
            RelationshipIndex relationshipIndex = this.rawGraph.index().forRelationships(indexName);
            if (relationshipIndex.isWriteable()) {
                relationshipIndex.delete();
            }
        }
        this.commit();
    }
View Full Code Here

            org.neo4j.graphdb.index.Index<Node> nodeIndex = this.rawGraph.index().forNodes(indexName);
            if (nodeIndex.isWriteable()) {
                nodeIndex.delete();
            }
        } else if (this.rawGraph.index().existsForRelationships(indexName)) {
            RelationshipIndex relationshipIndex = this.rawGraph.index().forRelationships(indexName);
            if (relationshipIndex.isWriteable()) {
                relationshipIndex.delete();
            }
        }
        this.commit();
    }
View Full Code Here

                log.warn("Cannot delete node index "+ix+" "+e.getMessage());
            }
        }
        for (String ix : indexManager.relationshipIndexNames()) {
            try {
                RelationshipIndex relationshipIndex = indexManager.forRelationships(ix);
                if (relationshipIndex.isWriteable()) relationshipIndex.delete();
            } catch(Exception e) {
                log.warn("Cannot delete relationship index "+ix+" "+e.getMessage());
            }
        }
    }
View Full Code Here

    }

    private void removeFromIndexes(Relationship relationship) {
        final IndexManager indexManager = delegate.index();
        for (String indexName : indexManager.relationshipIndexNames()) {
            RelationshipIndex relationshipIndex = indexManager.forRelationships(indexName);
            if (relationshipIndex.isWriteable()) relationshipIndex.remove(relationship);
        }
    }
View Full Code Here

        {
            // 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" );
View Full Code Here

    // public void getSameFromDifferentValuesO

    @Test
    public void doGetForRelationships()
    {
        RelationshipIndex roles = graphDb.index().forRelationships( "roles" );

        // START SNIPPET: getSingleRelationship
        Relationship persephone = roles.get( "name", "Persephone" ).getSingle();
        Node actor = persephone.getStartNode();
        Node movie = persephone.getEndNode();
        // END SNIPPET: getSingleRelationship

        assertEquals( "Monica Bellucci", actor.getProperty( "name" ) );
        assertEquals( "The Matrix Reloaded", movie.getProperty( "title" ) );

        @SuppressWarnings( "serial" ) List<String> expectedActors = new ArrayList<String>()
        {
            {
                add( "Keanu Reeves" );
                add( "Keanu Reeves" );
            }
        };
        List<String> foundActors = new ArrayList<String>();

        // START SNIPPET: getRelationships
        for ( Relationship role : roles.get( "name", "Neo" ) )
        {
            // this will give us Reeves twice
            Node reeves = role.getStartNode();
            // END SNIPPET: getRelationships
            foundActors.add( (String) reeves.getProperty( "name" ) );
View Full Code Here

    @Test
    public void doQueriesForRelationships()
    {
        IndexManager index = graphDb.index();
        RelationshipIndex roles = index.forRelationships( "roles" );
        Index<Node> actors = graphDb.index().forNodes( "actors" );
        Index<Node> movies = index.forNodes( "movies" );

        Node reeves = actors.get( "name", "Keanu Reeves" ).getSingle();
        Node theMatrix = movies.get( "title", "The Matrix" ).getSingle();

        // START SNIPPET: queryForRelationships
        // find relationships filtering on start node
        // using exact matches
        IndexHits<Relationship> reevesAsNeoHits;
        reevesAsNeoHits = roles.get( "name", "Neo", reeves, null );
        Relationship reevesAsNeo = reevesAsNeoHits.iterator().next();
        reevesAsNeoHits.close();
        // END SNIPPET: queryForRelationships
        assertEquals( "Neo", reevesAsNeo.getProperty( "name" ) );
        Node actor = reevesAsNeo.getStartNode();
        assertEquals( reeves, actor );

        // START SNIPPET: queryForRelationships
        // find relationships filtering on end node
        // using a query
        IndexHits<Relationship> matrixNeoHits;
        matrixNeoHits = roles.query( "name", "*eo", null, theMatrix );
        Relationship matrixNeo = matrixNeoHits.iterator().next();
        matrixNeoHits.close();
        // END SNIPPET: queryForRelationships
        assertEquals( "Neo", matrixNeo.getProperty( "name" ) );
        actor = matrixNeo.getStartNode();
        assertEquals( reeves, actor );

        // START SNIPPET: queryForRelationshipType
        // find relationships filtering on end node
        // using a relationship type.
        // this is how to add it to the index:
        roles.add( reevesAsNeo, "type", reevesAsNeo.getType().name() );
        // Note that to use a compound query, we can't combine committed
        // and uncommitted index entries, so we'll commit before querying:
        tx.success();
        tx.finish();
        // and now we can search for it:
        IndexHits<Relationship> typeHits;
        typeHits = roles.query( "type:ACTS_IN AND name:Neo", null, theMatrix );
        Relationship typeNeo = typeHits.iterator().next();
        typeHits.close();
        // END SNIPPET: queryForRelationshipType
        assertEquals( "Neo", typeNeo.getProperty( "name" ) );
        actor = matrixNeo.getStartNode();
View Full Code Here

    {
        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
        {
View Full Code Here

    }

    @Test
    public void testNodeLocalRelationshipIndex()
    {
        RelationshipIndex index = relationshipIndex( "locality",
                LuceneIndexImplementation.EXACT_CONFIG );

        RelationshipType type = DynamicRelationshipType.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( rel1, rel2 ) );
            assertThat( index.query( "name:something", null, endNode1 ), contains( rel1 ) );
            assertThat( index.query( "name:something", startNode, endNode2 ), contains( rel2 ) );
            assertThat( index.query( null, startNode, endNode1 ), contains( rel1 ) );
            assertThat( index.get( "name", "something", null, endNode1 ), contains( rel1 ) );
            assertThat( index.get( "name", "something", startNode, endNode2 ), contains( rel2 ) );
            assertThat( index.get( null, null, startNode, endNode1 ), contains( rel1 ) );
           
            restartTx();
        }
       
        rel2.delete();
        rel1.delete();
        startNode.delete();
        endNode1.delete();
        endNode2.delete();
        index.delete();
    }
View Full Code Here

TOP

Related Classes of org.neo4j.graphdb.index.RelationshipIndex

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.