Search in sources :

Example 1 with LuceneBatchInserterIndexProviderNewImpl

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();
    }
}
Also used : LuceneBatchInserterIndexProviderNewImpl(org.neo4j.index.impl.lucene.legacy.LuceneBatchInserterIndexProviderNewImpl) LuceneBatchInserterIndexProvider(org.neo4j.index.lucene.unsafe.batchinsert.LuceneBatchInserterIndexProvider) Transaction(org.neo4j.graphdb.Transaction) HashMap(java.util.HashMap) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 2 with LuceneBatchInserterIndexProviderNewImpl

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();
}
Also used : LuceneBatchInserterIndexProviderNewImpl(org.neo4j.index.impl.lucene.legacy.LuceneBatchInserterIndexProviderNewImpl) LuceneBatchInserterIndexProvider(org.neo4j.index.lucene.unsafe.batchinsert.LuceneBatchInserterIndexProvider) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with LuceneBatchInserterIndexProviderNewImpl

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();
    }
}
Also used : HashMap(java.util.HashMap) Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) LuceneBatchInserterIndexProviderNewImpl(org.neo4j.index.impl.lucene.legacy.LuceneBatchInserterIndexProviderNewImpl) IndexManager(org.neo4j.graphdb.index.IndexManager) LuceneBatchInserterIndexProvider(org.neo4j.index.lucene.unsafe.batchinsert.LuceneBatchInserterIndexProvider) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.Test)

Example 4 with LuceneBatchInserterIndexProviderNewImpl

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();
    }
}
Also used : LuceneBatchInserterIndexProviderNewImpl(org.neo4j.index.impl.lucene.legacy.LuceneBatchInserterIndexProviderNewImpl) LuceneBatchInserterIndexProvider(org.neo4j.index.lucene.unsafe.batchinsert.LuceneBatchInserterIndexProvider) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 5 with LuceneBatchInserterIndexProviderNewImpl

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();
}
Also used : LuceneBatchInserterIndexProviderNewImpl(org.neo4j.index.impl.lucene.legacy.LuceneBatchInserterIndexProviderNewImpl) LuceneBatchInserterIndexProvider(org.neo4j.index.lucene.unsafe.batchinsert.LuceneBatchInserterIndexProvider) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 LuceneBatchInserterIndexProviderNewImpl (org.neo4j.index.impl.lucene.legacy.LuceneBatchInserterIndexProviderNewImpl)10 LuceneBatchInserterIndexProvider (org.neo4j.index.lucene.unsafe.batchinsert.LuceneBatchInserterIndexProvider)10 Node (org.neo4j.graphdb.Node)5 Transaction (org.neo4j.graphdb.Transaction)5 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)1 IndexManager (org.neo4j.graphdb.index.IndexManager)1 ValueContext (org.neo4j.index.lucene.ValueContext)1