Search in sources :

Example 6 with LuceneBatchInserterIndexProviderNewImpl

use of org.neo4j.index.impl.lucene.legacy.LuceneBatchInserterIndexProviderNewImpl in project neo4j by neo4j.

the class TestLuceneBatchInsert method testFulltext.

@Test
public void testFulltext() {
    BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProviderNewImpl(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();
    switchToGraphDatabaseService();
    try (Transaction transaction = db.beginTx()) {
        Index<Node> dbIndex = db.index().forNodes(name);
        Node node1 = db.getNodeById(id1);
        Node node2 = db.getNodeById(id2);
        assertContains(dbIndex.query("name", "persson"), node1, node2);
        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 7 with LuceneBatchInserterIndexProviderNewImpl

use of org.neo4j.index.impl.lucene.legacy.LuceneBatchInserterIndexProviderNewImpl in project neo4j by neo4j.

the class TestLuceneBatchInsert method testNumericValueArrays.

@Test
public void testNumericValueArrays() {
    BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProviderNewImpl(inserter);
    BatchInserterIndex batchIndex = provider.nodeIndex("mine", EXACT_CONFIG);
    long nodeId1 = inserter.createNode(null);
    batchIndex.add(nodeId1, map("number", new ValueContext[] { numeric(45), numeric(98) }));
    long nodeId2 = inserter.createNode(null);
    batchIndex.add(nodeId2, map("number", new ValueContext[] { numeric(47), numeric(100) }));
    batchIndex.flush();
    IndexHits<Long> batchIndexResult1 = batchIndex.query("number", newIntRange("number", 47, 98, true, true));
    assertThat(batchIndexResult1, contains(nodeId1, nodeId2));
    assertThat(batchIndexResult1.size(), is(2));
    IndexHits<Long> batchIndexResult2 = batchIndex.query("number", newIntRange("number", 44, 46, true, true));
    assertThat(batchIndexResult2, contains(nodeId1));
    assertThat(batchIndexResult2.size(), is(1));
    IndexHits<Long> batchIndexResult3 = batchIndex.query("number", newIntRange("number", 99, 101, true, true));
    assertThat(batchIndexResult3, contains(nodeId2));
    assertThat(batchIndexResult3.size(), is(1));
    IndexHits<Long> batchIndexResult4 = batchIndex.query("number", newIntRange("number", 47, 98, false, false));
    assertThat(batchIndexResult4, Matchers.emptyIterable());
    provider.shutdown();
    switchToGraphDatabaseService();
    try (Transaction transaction = db.beginTx()) {
        Node node1 = db.getNodeById(nodeId1);
        Node node2 = db.getNodeById(nodeId2);
        Index<Node> index = db.index().forNodes("mine");
        IndexHits<Node> indexResult1 = index.query("number", newIntRange("number", 47, 98, true, true));
        assertThat(indexResult1, contains(node1, node2));
        assertThat(indexResult1.size(), is(2));
        IndexHits<Node> indexResult2 = index.query("number", newIntRange("number", 44, 46, true, true));
        assertThat(indexResult2, contains(node1));
        assertThat(indexResult2.size(), is(1));
        IndexHits<Node> indexResult3 = index.query("number", newIntRange("number", 99, 101, true, true));
        assertThat(indexResult3, contains(node2));
        assertThat(indexResult3.size(), is(1));
        IndexHits<Node> indexResult4 = index.query("number", newIntRange("number", 47, 98, false, false));
        assertThat(indexResult4, Matchers.emptyIterable());
        transaction.success();
    }
}
Also used : LuceneBatchInserterIndexProviderNewImpl(org.neo4j.index.impl.lucene.legacy.LuceneBatchInserterIndexProviderNewImpl) ValueContext(org.neo4j.index.lucene.ValueContext) LuceneBatchInserterIndexProvider(org.neo4j.index.lucene.unsafe.batchinsert.LuceneBatchInserterIndexProvider) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 8 with LuceneBatchInserterIndexProviderNewImpl

use of org.neo4j.index.impl.lucene.legacy.LuceneBatchInserterIndexProviderNewImpl in project neo4j by neo4j.

the class TestLuceneBatchInsert method indexNumbers.

@Test
public void indexNumbers() throws Exception {
    BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProviderNewImpl(inserter);
    BatchInserterIndex index = provider.nodeIndex("mine", EXACT_CONFIG);
    long id = inserter.createNode(null);
    Map<String, Object> props = new HashMap<>();
    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();
}
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 9 with LuceneBatchInserterIndexProviderNewImpl

use of org.neo4j.index.impl.lucene.legacy.LuceneBatchInserterIndexProviderNewImpl in project neo4j by neo4j.

the class TestLuceneBatchInsert method triggerNPEAfterFlush.

@Test
public void triggerNPEAfterFlush() {
    BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProviderNewImpl(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();
}
Also used : LuceneBatchInserterIndexProviderNewImpl(org.neo4j.index.impl.lucene.legacy.LuceneBatchInserterIndexProviderNewImpl) LuceneBatchInserterIndexProvider(org.neo4j.index.lucene.unsafe.batchinsert.LuceneBatchInserterIndexProvider) Test(org.junit.Test)

Example 10 with LuceneBatchInserterIndexProviderNewImpl

use of org.neo4j.index.impl.lucene.legacy.LuceneBatchInserterIndexProviderNewImpl in project neo4j by neo4j.

the class TestLuceneBatchInsert method testCanIndexRelationships.

@Test
public void testCanIndexRelationships() {
    BatchInserterIndexProvider indexProvider = new LuceneBatchInserterIndexProviderNewImpl(inserter);
    BatchInserterIndex edgesIndex = indexProvider.relationshipIndex("edgeIndex", stringMap(IndexManager.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();
}
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