Search in sources :

Example 6 with BatchInserterImpl

use of org.neo4j.kernel.impl.batchinsert.BatchInserterImpl in project graphdb by neo4j-attic.

the class ImdbExampleTest method batchInsert.

@Test
public void batchInsert() {
    // START SNIPPET: batchInsert
    BatchInserter inserter = new BatchInserterImpl("target/neo4jdb-batchinsert");
    BatchInserterIndexProvider indexProvider = new LuceneBatchInserterIndexProvider(inserter);
    BatchInserterIndex actors = indexProvider.nodeIndex("actors", MapUtil.stringMap("type", "exact"));
    actors.setCacheCapacity("name", 100000);
    Map<String, Object> properties = MapUtil.map("name", "Keanu Reeves");
    long node = inserter.createNode(properties);
    actors.add(node, properties);
    // Make sure to shut down the index provider
    indexProvider.shutdown();
    inserter.shutdown();
// END SNIPPET: batchInsert
}
Also used : BatchInserter(org.neo4j.kernel.impl.batchinsert.BatchInserter) BatchInserterImpl(org.neo4j.kernel.impl.batchinsert.BatchInserterImpl) BatchInserterIndexProvider(org.neo4j.graphdb.index.BatchInserterIndexProvider) LuceneBatchInserterIndexProvider(org.neo4j.index.impl.lucene.LuceneBatchInserterIndexProvider) LuceneBatchInserterIndexProvider(org.neo4j.index.impl.lucene.LuceneBatchInserterIndexProvider) BatchInserterIndex(org.neo4j.graphdb.index.BatchInserterIndex) Test(org.junit.Test)

Example 7 with BatchInserterImpl

use of org.neo4j.kernel.impl.batchinsert.BatchInserterImpl in project graphdb by neo4j-attic.

the class TestLuceneBatchInsert method testFindCreatedIndex.

@Test
public void testFindCreatedIndex() {
    String indexName = "persons";
    String path = new File(PATH, "4").getAbsolutePath();
    BatchInserter inserter = new BatchInserterImpl(path);
    LuceneBatchInserterIndexProvider indexProvider = new LuceneBatchInserterIndexProvider(inserter);
    BatchInserterIndex persons = indexProvider.nodeIndex("persons", stringMap("type", "exact"));
    Map<String, Object> properties = map("name", "test");
    long node = inserter.createNode(properties);
    persons.add(node, properties);
    indexProvider.shutdown();
    inserter.shutdown();
    GraphDatabaseService graphDb = new EmbeddedGraphDatabase(path);
    Transaction tx = graphDb.beginTx();
    try {
        IndexManager indexManager = graphDb.index();
        Assert.assertFalse(indexManager.existsForRelationships(indexName));
        Assert.assertTrue(indexManager.existsForNodes(indexName));
        Assert.assertNotNull(indexManager.forNodes(indexName));
        Index<Node> nodes = graphDb.index().forNodes(indexName);
        Assert.assertTrue(nodes.get("name", "test").hasNext());
        tx.success();
        tx.finish();
    } finally {
        graphDb.shutdown();
    }
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) BatchInserterImpl(org.neo4j.kernel.impl.batchinsert.BatchInserterImpl) Node(org.neo4j.graphdb.Node) IndexManager(org.neo4j.graphdb.index.IndexManager) BatchInserter(org.neo4j.kernel.impl.batchinsert.BatchInserter) Transaction(org.neo4j.graphdb.Transaction) BatchInserterIndex(org.neo4j.graphdb.index.BatchInserterIndex) File(java.io.File) Test(org.junit.Test)

Example 8 with BatchInserterImpl

use of org.neo4j.kernel.impl.batchinsert.BatchInserterImpl in project graphdb by neo4j-attic.

the class TestLuceneBatchInsert method testStartupAndShutdown.

@Test
public void testStartupAndShutdown() {
    BatchInserter inserter = new BatchInserterImpl(PATH);
    BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProvider(inserter);
    BatchInserterIndex index = provider.nodeIndex("users", LuceneIndexImplementation.EXACT_CONFIG);
    long id = inserter.createNode(null);
    index.add(id, map("name", "Joe", "other", "Schmoe"));
    provider.shutdown();
    provider = new LuceneBatchInserterIndexProvider(inserter);
    index = provider.nodeIndex("users", LuceneIndexImplementation.EXACT_CONFIG);
    index.add(id, map("name", "Joe", "other", "Schmoe"));
    provider.shutdown();
    inserter.shutdown();
}
Also used : BatchInserter(org.neo4j.kernel.impl.batchinsert.BatchInserter) BatchInserterImpl(org.neo4j.kernel.impl.batchinsert.BatchInserterImpl) BatchInserterIndexProvider(org.neo4j.graphdb.index.BatchInserterIndexProvider) BatchInserterIndex(org.neo4j.graphdb.index.BatchInserterIndex) Test(org.junit.Test)

Example 9 with BatchInserterImpl

use of org.neo4j.kernel.impl.batchinsert.BatchInserterImpl in project graphdb by neo4j-attic.

the class TestLuceneBatchInsert method testFulltext.

@Test
public void testFulltext() {
    String path = new File(PATH, "2").getAbsolutePath();
    BatchInserter inserter = new BatchInserterImpl(path);
    BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProvider(inserter);
    String name = "users";
    BatchInserterIndex index = provider.nodeIndex(name, stringMap("type", "fulltext"));
    long id1 = inserter.createNode(null);
    index.add(id1, map("name", "Mattias Persson", "email", "something@somewhere", "something", "bad"));
    long id2 = inserter.createNode(null);
    index.add(id2, map("name", "Lars PerssoN"));
    index.flush();
    assertContains(index.get("name", "Mattias Persson"), id1);
    assertContains(index.query("name", "mattias"), id1);
    assertContains(index.query("name", "bla"));
    assertContains(index.query("name", "persson"), id1, id2);
    assertContains(index.query("email", "*@*"), id1);
    assertContains(index.get("something", "bad"), id1);
    long id3 = inserter.createNode(null);
    index.add(id3, map("name", new String[] { "What Ever", "Anything" }));
    index.flush();
    assertContains(index.get("name", "What Ever"), id3);
    assertContains(index.get("name", "Anything"), id3);
    provider.shutdown();
    inserter.shutdown();
    GraphDatabaseService db = new EmbeddedGraphDatabase(path);
    Index<Node> dbIndex = db.index().forNodes(name);
    Node node1 = db.getNodeById(id1);
    Node node2 = db.getNodeById(id2);
    assertContains(dbIndex.query("name", "persson"), node1, node2);
    db.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) BatchInserter(org.neo4j.kernel.impl.batchinsert.BatchInserter) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) BatchInserterImpl(org.neo4j.kernel.impl.batchinsert.BatchInserterImpl) BatchInserterIndexProvider(org.neo4j.graphdb.index.BatchInserterIndexProvider) BatchInserterIndex(org.neo4j.graphdb.index.BatchInserterIndex) Node(org.neo4j.graphdb.Node) File(java.io.File) Test(org.junit.Test)

Example 10 with BatchInserterImpl

use of org.neo4j.kernel.impl.batchinsert.BatchInserterImpl in project graphdb by neo4j-attic.

the class TestLuceneBatchInsert method testCanIndexRelationships.

@Test
public void testCanIndexRelationships() {
    BatchInserter inserter = new BatchInserterImpl(new File(PATH, "5").getAbsolutePath());
    BatchInserterIndexProvider indexProvider = new LuceneBatchInserterIndexProvider(inserter);
    BatchInserterIndex edgesIndex = indexProvider.relationshipIndex("edgeIndex", stringMap("provider", "lucene", "type", "exact"));
    long nodeId1 = inserter.createNode(map("ID", "1"));
    long nodeId2 = inserter.createNode(map("ID", "2"));
    long relationshipId = inserter.createRelationship(nodeId1, nodeId2, EdgeType.KNOWS, null);
    edgesIndex.add(relationshipId, map("EDGE_TYPE", EdgeType.KNOWS.name()));
    edgesIndex.flush();
    assertEquals(String.format("Should return relationship id"), new Long(relationshipId), edgesIndex.query("EDGE_TYPE", EdgeType.KNOWS.name()).getSingle());
    indexProvider.shutdown();
    inserter.shutdown();
}
Also used : BatchInserter(org.neo4j.kernel.impl.batchinsert.BatchInserter) BatchInserterImpl(org.neo4j.kernel.impl.batchinsert.BatchInserterImpl) BatchInserterIndexProvider(org.neo4j.graphdb.index.BatchInserterIndexProvider) BatchInserterIndex(org.neo4j.graphdb.index.BatchInserterIndex) File(java.io.File) Test(org.junit.Test)

Aggregations

BatchInserterImpl (org.neo4j.kernel.impl.batchinsert.BatchInserterImpl)13 Test (org.junit.Test)12 BatchInserter (org.neo4j.kernel.impl.batchinsert.BatchInserter)11 File (java.io.File)10 BatchInserterIndex (org.neo4j.graphdb.index.BatchInserterIndex)10 BatchInserterIndexProvider (org.neo4j.graphdb.index.BatchInserterIndexProvider)9 EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)6 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)5 Node (org.neo4j.graphdb.Node)5 HashMap (java.util.HashMap)2 Transaction (org.neo4j.graphdb.Transaction)2 ArrayList (java.util.ArrayList)1 Ignore (org.junit.Ignore)1 IndexManager (org.neo4j.graphdb.index.IndexManager)1 LuceneBatchInserterIndexProvider (org.neo4j.index.impl.lucene.LuceneBatchInserterIndexProvider)1