Search in sources :

Example 6 with BatchInserterIndexProvider

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

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

Example 8 with BatchInserterIndexProvider

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

the class TestLuceneBatchInsert method triggerNPEAfterFlush.

@Test
public void triggerNPEAfterFlush() {
    BatchInserter inserter = new BatchInserterImpl(new File(PATH, "6").getAbsolutePath());
    BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProvider(inserter);
    BatchInserterIndex index = provider.nodeIndex("Node-exact", EXACT_CONFIG);
    Map<String, Object> map = map("name", "Something");
    long node = inserter.createNode(map);
    index.add(node, map);
    index.flush();
    assertContains(index.get("name", "Something"), node);
    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) File(java.io.File) Test(org.junit.Test)

Example 9 with BatchInserterIndexProvider

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

the class TestLuceneBatchInsert method testSome.

@Test
public void testSome() throws Exception {
    // Different paths for each tests because there's a bug (on Windows)
    // causing _0.cfs file to stay open 
    String path = new File(PATH, "1").getAbsolutePath();
    BatchInserter inserter = new BatchInserterImpl(path);
    BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProvider(inserter);
    BatchInserterIndex index = provider.nodeIndex("users", EXACT_CONFIG);
    Map<Integer, Long> ids = new HashMap<Integer, Long>();
    for (int i = 0; i < 100; i++) {
        long id = inserter.createNode(null);
        index.add(id, map("name", "Joe" + i, "other", "Schmoe"));
        ids.put(i, id);
    }
    for (int i = 0; i < 100; i++) {
        assertContains(index.get("name", "Joe" + i), ids.get(i));
    }
    assertContains(index.query("name:Joe0 AND other:Schmoe"), ids.get(0));
    assertContains(index.query("name", "Joe*"), ids.values().toArray(new Long[ids.size()]));
    provider.shutdown();
    inserter.shutdown();
    GraphDatabaseService db = new EmbeddedGraphDatabase(path);
    assertTrue(db.index().existsForNodes("users"));
    Index<Node> dbIndex = db.index().forNodes("users");
    for (int i = 0; i < 100; i++) {
        assertContains(dbIndex.get("name", "Joe" + i), db.getNodeById(ids.get(i)));
    }
    Collection<Node> nodes = new ArrayList<Node>();
    for (long id : ids.values()) {
        nodes.add(db.getNodeById(id));
    }
    assertContains(dbIndex.query("name", "Joe*"), nodes.toArray(new Node[nodes.size()]));
    assertContains(dbIndex.query("name:Joe0 AND other:Schmoe"), db.getNodeById(ids.get(0)));
    db.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) BatchInserterImpl(org.neo4j.kernel.impl.batchinsert.BatchInserterImpl) HashMap(java.util.HashMap) Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) BatchInserter(org.neo4j.kernel.impl.batchinsert.BatchInserter) BatchInserterIndexProvider(org.neo4j.graphdb.index.BatchInserterIndexProvider) BatchInserterIndex(org.neo4j.graphdb.index.BatchInserterIndex) File(java.io.File) Test(org.junit.Test)

Aggregations

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