Search in sources :

Example 16 with IndexReaderStub

use of org.neo4j.kernel.api.impl.index.IndexReaderStub in project neo4j by neo4j.

the class DocValuesCollectorTest method shouldSilentlyMergeSegmentsWhenReadingDocValues.

@Test
public void shouldSilentlyMergeSegmentsWhenReadingDocValues() throws Exception {
    // given
    DocValuesCollector collector = new DocValuesCollector(false);
    IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
    // when
    collector.doSetNextReader(readerStub.getContext());
    collector.collect(1);
    collector.doSetNextReader(readerStub.getContext());
    collector.collect(2);
    // then
    DocValuesCollector.LongValuesIterator valuesIterator = collector.getValuesIterator("id");
    assertEquals(2, valuesIterator.remaining());
    assertEquals(1, valuesIterator.next());
    assertEquals(2, valuesIterator.next());
    assertFalse(valuesIterator.hasNext());
}
Also used : IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) Test(org.junit.Test)

Example 17 with IndexReaderStub

use of org.neo4j.kernel.api.impl.index.IndexReaderStub in project neo4j by neo4j.

the class DocValuesCollectorTest method shouldReturnIndexHitsInIndexOrderWhenNoSortIsGiven.

@Test
public void shouldReturnIndexHitsInIndexOrderWhenNoSortIsGiven() throws Exception {
    // given
    DocValuesCollector collector = new DocValuesCollector();
    IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
    // when
    collector.doSetNextReader(readerStub.getContext());
    collector.collect(1);
    collector.collect(2);
    // then
    IndexHits<Document> indexHits = collector.getIndexHits(null);
    assertEquals(2, indexHits.size());
    assertEquals("1", indexHits.next().get("id"));
    assertEquals("2", indexHits.next().get("id"));
    assertFalse(indexHits.hasNext());
}
Also used : IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) Document(org.apache.lucene.document.Document) Test(org.junit.Test)

Example 18 with IndexReaderStub

use of org.neo4j.kernel.api.impl.index.IndexReaderStub in project neo4j by neo4j.

the class DocValuesCollectorTest method shouldSilentlyMergeAllSegments.

@Test
public void shouldSilentlyMergeAllSegments() throws Exception {
    // given
    DocValuesCollector collector = new DocValuesCollector(false);
    IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
    // when
    collector.doSetNextReader(readerStub.getContext());
    collector.collect(1);
    collector.doSetNextReader(readerStub.getContext());
    collector.collect(2);
    // then
    IndexHits<Document> indexHits = collector.getIndexHits(null);
    assertEquals(2, indexHits.size());
    assertEquals("1", indexHits.next().get("id"));
    assertEquals("2", indexHits.next().get("id"));
    assertFalse(indexHits.hasNext());
}
Also used : IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) Document(org.apache.lucene.document.Document) Test(org.junit.Test)

Example 19 with IndexReaderStub

use of org.neo4j.kernel.api.impl.index.IndexReaderStub in project neo4j by neo4j.

the class DocValuesCollectorTest method shouldReturnDocValuesInGivenOrder.

@Test
public void shouldReturnDocValuesInGivenOrder() throws Exception {
    // given
    DocValuesCollector collector = new DocValuesCollector(false);
    IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
    // when
    collector.doSetNextReader(readerStub.getContext());
    collector.collect(1);
    collector.collect(2);
    // then
    Sort byIdDescending = new Sort(new SortField("id", SortField.Type.LONG, true));
    PrimitiveLongIterator valuesIterator = collector.getSortedValuesIterator("id", byIdDescending);
    assertEquals(2, valuesIterator.next());
    assertEquals(1, valuesIterator.next());
    assertFalse(valuesIterator.hasNext());
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) Sort(org.apache.lucene.search.Sort) SortField(org.apache.lucene.search.SortField) Test(org.junit.Test)

Example 20 with IndexReaderStub

use of org.neo4j.kernel.api.impl.index.IndexReaderStub in project neo4j by neo4j.

the class DocValuesCollectorTest method shouldDynamicallyResizeScoresArray.

@Test
void shouldDynamicallyResizeScoresArray() throws Exception {
    // given
    DocValuesCollector collector = new DocValuesCollector(true);
    IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
    // when
    collector.doSetNextReader(readerStub.getContext());
    collector.setScorer(constantScorer(1.0f));
    // scores starts with array size of 32, adding 42 docs forces resize
    for (int i = 0; i < 42; i++) {
        collector.collect(i);
    }
    // then
    DocValuesCollector.MatchingDocs matchingDocs = collector.getMatchingDocs().get(0);
    float[] scores = new float[42];
    Arrays.fill(scores, 1.0f);
    assertArrayEquals(scores, matchingDocs.scores, 0.001f);
}
Also used : IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) Test(org.junit.jupiter.api.Test)

Aggregations

IndexReaderStub (org.neo4j.kernel.api.impl.index.IndexReaderStub)25 Test (org.junit.jupiter.api.Test)13 Test (org.junit.Test)11 Document (org.apache.lucene.document.Document)5 LongIterator (org.eclipse.collections.api.iterator.LongIterator)3 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 NumericDocValues (org.apache.lucene.index.NumericDocValues)2 Terms (org.apache.lucene.index.Terms)2 DocIdSetIterator (org.apache.lucene.search.DocIdSetIterator)2 Sort (org.apache.lucene.search.Sort)2 SortField (org.apache.lucene.search.SortField)2 IndexProgressor (org.neo4j.kernel.api.index.IndexProgressor)2 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 Query (org.apache.lucene.search.Query)1 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)1 DocValuesCollector (org.neo4j.kernel.api.impl.index.collector.DocValuesCollector)1 IndexSample (org.neo4j.kernel.api.index.IndexSample)1