Search in sources :

Example 16 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class SimpleIndexReaderTest method scanQueryReachSearcher.

@Test
public void scanQueryReachSearcher() throws Exception {
    IndexReader simpleIndexReader = getUniqueSimpleReader();
    simpleIndexReader.query(IndexQuery.exists(1));
    verify(indexSearcher).search(any(MatchAllDocsQuery.class), any(DocValuesCollector.class));
}
Also used : DocValuesCollector(org.neo4j.kernel.api.impl.index.collector.DocValuesCollector) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) Test(org.junit.Test)

Example 17 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class UniqueDatabaseIndexPopulatorTest method addUpdates.

@Test
public void addUpdates() throws Exception {
    populator = newPopulator();
    List<IndexEntryUpdate> updates = Arrays.asList(IndexEntryUpdate.add(1, descriptor.schema(), "aaa"), IndexEntryUpdate.add(2, descriptor.schema(), "bbb"), IndexEntryUpdate.add(3, descriptor.schema(), "ccc"));
    populator.add(updates);
    index.maybeRefreshBlocking();
    try (IndexReader reader = index.getIndexReader()) {
        PrimitiveLongIterator allEntities = reader.query(IndexQuery.exists(1));
        assertArrayEquals(new long[] { 1, 2, 3 }, PrimitiveLongCollections.asArray(allEntities));
    }
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Example 18 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class LuceneSchemaIndexPopulationIT method partitionedIndexPopulation.

@Test
public void partitionedIndexPopulation() throws Exception {
    try (SchemaIndex uniqueIndex = LuceneSchemaIndexBuilder.create(descriptor).withFileSystem(fileSystemRule.get()).withIndexRootFolder(testDir.directory("partitionIndex" + affectedNodes)).withIndexIdentifier("uniqueIndex" + affectedNodes).build()) {
        uniqueIndex.open();
        // index is empty and not yet exist
        assertEquals(0, uniqueIndex.allDocumentsReader().maxCount());
        assertFalse(uniqueIndex.exists());
        try (LuceneIndexAccessor indexAccessor = new LuceneIndexAccessor(uniqueIndex, descriptor)) {
            generateUpdates(indexAccessor, affectedNodes);
            indexAccessor.force();
            // now index is online and should contain updates data
            assertTrue(uniqueIndex.isOnline());
            try (IndexReader indexReader = indexAccessor.newReader()) {
                long[] nodes = PrimitiveLongCollections.asArray(indexReader.query(IndexQuery.exists(1)));
                assertEquals(affectedNodes, nodes.length);
                IndexSampler indexSampler = indexReader.createSampler();
                IndexSample sample = indexSampler.sampleIndex();
                assertEquals(affectedNodes, sample.indexSize());
                assertEquals(affectedNodes, sample.uniqueValues());
                assertEquals(affectedNodes, sample.sampleSize());
            }
        }
    }
}
Also used : LuceneIndexAccessor(org.neo4j.kernel.api.impl.schema.LuceneIndexAccessor) IndexSample(org.neo4j.storageengine.api.schema.IndexSample) SchemaIndex(org.neo4j.kernel.api.impl.schema.SchemaIndex) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) IndexSampler(org.neo4j.storageengine.api.schema.IndexSampler) Test(org.junit.Test)

Example 19 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class DatabaseCompositeIndexAccessorTest method indexReaderShouldSupportScan.

@Test
public void indexReaderShouldSupportScan() throws Exception {
    // GIVEN
    updateAndCommit(asList(add(nodeId, values), add(nodeId2, values2)));
    IndexReader reader = accessor.newReader();
    // WHEN
    PrimitiveLongIterator results = reader.query(IndexQuery.exists(PROP_ID1), IndexQuery.exists(PROP_ID2));
    // THEN
    assertEquals(asSet(nodeId, nodeId2), PrimitiveLongCollections.toSet(results));
    assertEquals(asSet(nodeId), PrimitiveLongCollections.toSet(reader.query(IndexQuery.exact(PROP_ID1, values[0]), IndexQuery.exact(PROP_ID2, values[1]))));
    reader.close();
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Example 20 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class DatabaseCompositeIndexAccessorTest method canRemoveExistingData.

@Test
public void canRemoveExistingData() throws Exception {
    // GIVEN
    updateAndCommit(asList(add(nodeId, values), add(nodeId2, values2)));
    // WHEN
    updateAndCommit(asList(remove(nodeId, values)));
    IndexReader reader = accessor.newReader();
    // THEN
    assertEquals(asSet(nodeId2), PrimitiveLongCollections.toSet(reader.query(IndexQuery.exact(PROP_ID1, values2[0]), IndexQuery.exact(PROP_ID2, values2[1]))));
    assertEquals(asSet(), PrimitiveLongCollections.toSet(reader.query(IndexQuery.exact(PROP_ID1, values[0]), IndexQuery.exact(PROP_ID2, values[1]))));
    reader.close();
}
Also used : IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Aggregations

IndexReader (org.neo4j.storageengine.api.schema.IndexReader)50 Test (org.junit.Test)38 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)19 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)11 StateHandlingStatementOperations (org.neo4j.kernel.impl.api.StateHandlingStatementOperations)10 StoreReadLayer (org.neo4j.storageengine.api.StoreReadLayer)10 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)9 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)9 DocValuesCollector (org.neo4j.kernel.api.impl.index.collector.DocValuesCollector)6 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)5 IndexSampler (org.neo4j.storageengine.api.schema.IndexSampler)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Arrays (java.util.Arrays)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 TermQuery (org.apache.lucene.search.TermQuery)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.fail (org.junit.Assert.fail)2 Before (org.junit.Before)2