Search in sources :

Example 1 with BatchInserterIndex

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

the class TestLuceneBatchInsert method testNumericValues.

@Test
public void testNumericValues() {
    String path = new File(PATH, "7").getAbsolutePath();
    BatchInserter inserter = new BatchInserterImpl(path);
    BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProvider(inserter);
    BatchInserterIndex index = provider.nodeIndex("mine", EXACT_CONFIG);
    long node1 = inserter.createNode(null);
    index.add(node1, map("number", numeric(45)));
    long node2 = inserter.createNode(null);
    index.add(node2, map("number", numeric(21)));
    assertContains(index.query("number", newIntRange("number", 21, 50, true, true)), node1, node2);
    provider.shutdown();
    inserter.shutdown();
    GraphDatabaseService db = new EmbeddedGraphDatabase(path);
    Node n1 = db.getNodeById(node1);
    Node n2 = db.getNodeById(node2);
    Index<Node> idx = db.index().forNodes("mine");
    assertContains(idx.query("number", newIntRange("number", 21, 45, false, true)), n1);
    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 2 with BatchInserterIndex

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

the class TestLuceneBatchInsert method indexNumbers.

@Test
public void indexNumbers() throws Exception {
    BatchInserter inserter = new BatchInserterImpl(new File(PATH, "8").getAbsolutePath());
    BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProvider(inserter);
    BatchInserterIndex index = provider.nodeIndex("mine", EXACT_CONFIG);
    long id = inserter.createNode(null);
    Map<String, Object> props = new HashMap<String, Object>();
    props.put("key", 123L);
    index.add(id, props);
    index.flush();
    assertEquals(1, index.get("key", 123L).size());
    assertEquals(1, index.get("key", "123").size());
    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) HashMap(java.util.HashMap) BatchInserterIndex(org.neo4j.graphdb.index.BatchInserterIndex) File(java.io.File) Test(org.junit.Test)

Example 3 with BatchInserterIndex

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

the class TestLuceneBatchInsert method testInsertionSpeed.

@Ignore
@Test
public void testInsertionSpeed() {
    BatchInserter inserter = new BatchInserterImpl(new File(PATH, "3").getAbsolutePath());
    BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProvider(inserter);
    BatchInserterIndex index = provider.nodeIndex("yeah", EXACT_CONFIG);
    index.setCacheCapacity("key", 1000000);
    long t = currentTimeMillis();
    for (int i = 0; i < 1000000; i++) {
        Map<String, Object> properties = map("key", "value" + i);
        long id = inserter.createNode(properties);
        index.add(id, properties);
    }
    System.out.println("insert:" + (currentTimeMillis() - t));
    index.flush();
    t = currentTimeMillis();
    for (int i = 0; i < 1000000; i++) {
        count((Iterator<Long>) index.get("key", "value" + i));
    }
    System.out.println("get:" + (currentTimeMillis() - t));
}
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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with BatchInserterIndex

use of org.neo4j.graphdb.index.BatchInserterIndex 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 5 with BatchInserterIndex

use of org.neo4j.graphdb.index.BatchInserterIndex 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)

Aggregations

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