use of org.neo4j.index.impl.lucene.legacy.LuceneBatchInserterIndexProviderNewImpl in project neo4j by neo4j.
the class TestLuceneBatchInsert method shouldCreateAutoIndexThatIsUsableInEmbedded.
@Test
public void shouldCreateAutoIndexThatIsUsableInEmbedded() throws Exception {
BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProviderNewImpl(inserter);
BatchInserterIndex index = provider.nodeIndex("node_auto_index", EXACT_CONFIG);
long id = inserter.createNode(null);
Map<String, Object> props = new HashMap<>();
props.put("name", "peter");
index.add(id, props);
index.flush();
provider.shutdown();
shutdownInserter();
switchToGraphDatabaseService(configure(GraphDatabaseSettings.node_keys_indexable, "name"), configure(GraphDatabaseSettings.relationship_keys_indexable, "relProp1,relProp2"), configure(GraphDatabaseSettings.node_auto_indexing, "true"), configure(GraphDatabaseSettings.relationship_auto_indexing, "true"));
try (Transaction tx = db.beginTx()) {
// Create the primitives
Node node1 = db.createNode();
// Add indexable and non-indexable properties
node1.setProperty("name", "bob");
// Make things persistent
tx.success();
}
try (Transaction tx = db.beginTx()) {
assertTrue(db.index().getNodeAutoIndexer().getAutoIndex().get("name", "peter").hasNext());
assertTrue(db.index().getNodeAutoIndexer().getAutoIndex().get("name", "bob").hasNext());
assertFalse(db.index().getNodeAutoIndexer().getAutoIndex().get("name", "joe").hasNext());
tx.success();
}
}
use of org.neo4j.index.impl.lucene.legacy.LuceneBatchInserterIndexProviderNewImpl in project neo4j by neo4j.
the class TestLuceneBatchInsert method addOrUpdateFlushBehaviour.
@Test
public void addOrUpdateFlushBehaviour() throws Exception {
BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProviderNewImpl(inserter);
BatchInserterIndex index = provider.nodeIndex("update", EXACT_CONFIG);
long id = inserter.createNode(null);
Map<String, Object> props = new HashMap<>();
props.put("key", "value");
index.add(id, props);
index.updateOrAdd(id, props);
index.flush();
assertEquals(1, index.get("key", "value").size());
index.flush();
props.put("key", "value2");
index.updateOrAdd(id, props);
index.flush();
assertEquals(1, index.get("key", "value2").size());
assertEquals(0, index.get("key", "value").size());
props.put("key2", "value2");
props.put("key", "value");
index.updateOrAdd(id, props);
assertEquals(0, index.get("key2", "value2").size());
index.flush();
assertEquals(1, index.get("key2", "value2").size());
assertEquals(1, index.get("key", "value").size());
long id2 = inserter.createNode(null);
props = new HashMap<>();
props.put("2key", "value");
index.updateOrAdd(id2, props);
props.put("2key", "value2");
props.put("2key2", "value3");
index.updateOrAdd(id2, props);
index.flush();
assertEquals(1, index.get("2key", "value2").size());
provider.shutdown();
}
use of org.neo4j.index.impl.lucene.legacy.LuceneBatchInserterIndexProviderNewImpl in project neo4j by neo4j.
the class TestLuceneBatchInsert method testSome.
@Test
public void testSome() throws Exception {
BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProviderNewImpl(inserter);
String indexName = "users";
BatchInserterIndex index = provider.nodeIndex(indexName, EXACT_CONFIG);
Map<Integer, Long> ids = new HashMap<>();
int count = 5;
for (int i = 0; i < count; i++) {
long id = inserter.createNode(null);
index.add(id, map("name", "Joe" + i, "other", "Schmoe"));
ids.put(i, id);
}
index.flush();
for (int i = 0; i < count; 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();
switchToGraphDatabaseService();
try (Transaction transaction = db.beginTx()) {
IndexManager indexManager = db.index();
assertFalse(indexManager.existsForRelationships(indexName));
assertTrue(indexManager.existsForNodes(indexName));
assertNotNull(indexManager.forNodes(indexName));
Index<Node> dbIndex = db.index().forNodes("users");
for (int i = 0; i < count; i++) {
assertContains(dbIndex.get("name", "Joe" + i), db.getNodeById(ids.get(i)));
}
Collection<Node> nodes = new ArrayList<>();
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)));
transaction.success();
}
}
use of org.neo4j.index.impl.lucene.legacy.LuceneBatchInserterIndexProviderNewImpl in project neo4j by neo4j.
the class TestLuceneBatchInsert method testNumericValues.
@Test
public void testNumericValues() {
BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProviderNewImpl(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)));
index.flush();
assertContains(index.query("number", newIntRange("number", 21, 50, true, true)), node1, node2);
provider.shutdown();
switchToGraphDatabaseService();
try (Transaction transaction = db.beginTx()) {
Node n1 = db.getNodeById(node1);
db.getNodeById(node2);
Index<Node> idx = db.index().forNodes("mine");
assertContains(idx.query("number", newIntRange("number", 21, 45, false, true)), n1);
transaction.success();
}
}
use of org.neo4j.index.impl.lucene.legacy.LuceneBatchInserterIndexProviderNewImpl in project neo4j by neo4j.
the class TestLuceneBatchInsert method useStandardAnalyzer.
@Test
public void useStandardAnalyzer() throws Exception {
BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProviderNewImpl(inserter);
BatchInserterIndex index = provider.nodeIndex("myindex", stringMap("analyzer", MyStandardAnalyzer.class.getName()));
index.add(0, map("name", "Mattias"));
provider.shutdown();
}
Aggregations