use of org.neo4j.kernel.impl.batchinsert.BatchInserter 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();
}
Aggregations