Search in sources :

Example 6 with IndexManager

use of org.neo4j.graphdb.index.IndexManager in project neo4j-mobile-android by neo4j-contrib.

the class DbWrapper method createNodeIndex.

// -------------------------------------------------------------------------
// Node Indexing support
// -------------------------------------------------------------------------
@Override
public void createNodeIndex(String name, ParcelableError err) throws RemoteException {
    try {
        checkCallerHasWritePermission();
        resumeTrx();
        try {
            IndexManager index = mDb.index();
            // this will create the index
            index.forNodes(name);
        } finally {
            suspendCurrentTrx("createNodeIndex");
        }
    } catch (Exception e) {
        Log.e(TAG, "Failed to create/access node index '" + name + "'", e);
        err.setError(Errors.TRANSACTION, e.getMessage());
    }
}
Also used : IndexManager(org.neo4j.graphdb.index.IndexManager) RemoteException(android.os.RemoteException) InvalidTransactionException(org.neo4j.javax.transaction.InvalidTransactionException) SystemException(org.neo4j.javax.transaction.SystemException)

Example 7 with IndexManager

use of org.neo4j.graphdb.index.IndexManager 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();
    }
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) IndexManager(org.neo4j.graphdb.index.IndexManager) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipIndex(org.neo4j.graphdb.index.RelationshipIndex) DynamicRelationshipType(org.neo4j.graphdb.DynamicRelationshipType) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 8 with IndexManager

use of org.neo4j.graphdb.index.IndexManager in project graphdb by neo4j-attic.

the class ImdbExampleTest method update.

@Test
public void update() {
    IndexManager index = graphDb.index();
    Index<Node> actors = index.forNodes("actors");
    // START SNIPPET: update
    // create a node with a property
    Node fishburn = graphDb.createNode();
    fishburn.setProperty("name", "Fishburn");
    // index it
    actors.add(fishburn, "name", fishburn.getProperty("name"));
    // END SNIPPET: update
    Node node = actors.get("name", "Fishburn").getSingle();
    assertEquals(fishburn, node);
    // START SNIPPET: update
    // update the index entry
    actors.remove(fishburn, "name", fishburn.getProperty("name"));
    fishburn.setProperty("name", "Laurence Fishburn");
    actors.add(fishburn, "name", fishburn.getProperty("name"));
    // END SNIPPET: update
    node = actors.get("name", "Fishburn").getSingle();
    assertEquals(null, node);
    node = actors.get("name", "Laurence Fishburn").getSingle();
    assertEquals(fishburn, node);
}
Also used : IndexManager(org.neo4j.graphdb.index.IndexManager) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 9 with IndexManager

use of org.neo4j.graphdb.index.IndexManager in project graphdb by neo4j-attic.

the class ImdbExampleTest method deleteIndex.

@Test
public void deleteIndex() {
    GraphDatabaseService graphDb = new EmbeddedGraphDatabase("target/graphdb-delete");
    Transaction transaction = graphDb.beginTx();
    try {
        // START SNIPPET: delete
        IndexManager index = graphDb.index();
        Index<Node> actors = index.forNodes("actors");
        actors.delete();
        // END SNIPPET: delete
        transaction.success();
    } finally {
        transaction.finish();
    }
    assertFalse(graphDb.index().existsForNodes("actors"));
    graphDb.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) IndexManager(org.neo4j.graphdb.index.IndexManager) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 10 with IndexManager

use of org.neo4j.graphdb.index.IndexManager in project graphdb by neo4j-attic.

the class ImdbExampleTest method fulltext.

@Test
public void fulltext() {
    // START SNIPPET: fulltext
    IndexManager index = graphDb.index();
    Index<Node> fulltextMovies = index.forNodes("movies-fulltext", MapUtil.stringMap("provider", "lucene", "type", "fulltext"));
    // END SNIPPET: fulltext
    Index<Node> movies = index.forNodes("movies");
    Node theMatrix = movies.get("title", "The Matrix").getSingle();
    Node theMatrixReloaded = movies.get("title", "The Matrix Reloaded").getSingle();
    // START SNIPPET: fulltext
    fulltextMovies.add(theMatrix, "title", "The Matrix");
    fulltextMovies.add(theMatrixReloaded, "title", "The Matrix Reloaded");
    // search in the fulltext index
    Node found = fulltextMovies.query("title", "reloAdEd").getSingle();
    // END SNIPPET: fulltext
    assertEquals(theMatrixReloaded, found);
}
Also used : IndexManager(org.neo4j.graphdb.index.IndexManager) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Aggregations

IndexManager (org.neo4j.graphdb.index.IndexManager)16 Node (org.neo4j.graphdb.Node)13 Test (org.junit.Test)10 Transaction (org.neo4j.graphdb.Transaction)6 Relationship (org.neo4j.graphdb.Relationship)4 RelationshipIndex (org.neo4j.graphdb.index.RelationshipIndex)3 EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)3 RemoteException (android.os.RemoteException)2 File (java.io.File)2 HashMap (java.util.HashMap)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 Index (org.neo4j.graphdb.index.Index)2 InvalidTransactionException (org.neo4j.javax.transaction.InvalidTransactionException)2 SystemException (org.neo4j.javax.transaction.SystemException)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Random (java.util.Random)1 Term (org.apache.lucene.index.Term)1 TermQuery (org.apache.lucene.search.TermQuery)1