Search in sources :

Example 6 with IndexReaderStub

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

the class DocValuesCollectorTest method shouldReturnIndexHitsInGivenSortOrder.

@Test
public void shouldReturnIndexHitsInGivenSortOrder() throws Exception {
    // given
    DocValuesCollector collector = new DocValuesCollector(false);
    IndexReaderStub readerStub = indexReaderWithMaxDocs(43);
    // when
    collector.doSetNextReader(readerStub.getContext());
    collector.collect(1);
    collector.collect(3);
    collector.collect(37);
    collector.collect(42);
    // then
    Sort byIdDescending = new Sort(new SortField("id", SortField.Type.LONG, true));
    IndexHits<Document> indexHits = collector.getIndexHits(byIdDescending);
    assertEquals(4, indexHits.size());
    assertEquals("42", indexHits.next().get("id"));
    assertEquals("37", indexHits.next().get("id"));
    assertEquals("3", indexHits.next().get("id"));
    assertEquals("1", indexHits.next().get("id"));
    assertFalse(indexHits.hasNext());
}
Also used : IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) Sort(org.apache.lucene.search.Sort) SortField(org.apache.lucene.search.SortField) Document(org.apache.lucene.document.Document) Test(org.junit.Test)

Example 7 with IndexReaderStub

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

the class DocValuesCollectorTest method shouldReturnEmptyIteratorWhenNoDocValues.

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

Example 8 with IndexReaderStub

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

the class NonUniqueDatabaseIndexSamplerTest method nonUniqueIndexSampling.

@Test
void nonUniqueIndexSampling() throws Exception {
    Terms aTerms = getTerms("a", 1);
    Terms idTerms = getTerms("id", 2);
    Terms bTerms = getTerms("b", 3);
    Map<String, Terms> fieldTermsMap = MapUtil.genericMap("0string", aTerms, "id", idTerms, "0array", bTerms);
    IndexReaderStub indexReader = new IndexReaderStub(new SamplingFields(fieldTermsMap));
    indexReader.setElements(new String[4]);
    when(indexSearcher.getIndexReader()).thenReturn(indexReader);
    assertEquals(new IndexSample(4, 2, 4), createSampler().sampleIndex(NULL));
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) Terms(org.apache.lucene.index.Terms) Test(org.junit.jupiter.api.Test)

Example 9 with IndexReaderStub

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

the class DocValuesCollectorTest method indexReaderWithMaxDocs.

private static IndexReaderStub indexReaderWithMaxDocs(int maxDocs) {
    NumericDocValues identityValues = new NumericDocValues() {

        @Override
        public boolean advanceExact(int target) {
            advance(target);
            return true;
        }

        private int next = -1;

        @Override
        public int docID() {
            return next;
        }

        @Override
        public int nextDoc() {
            return advance(next + 1);
        }

        @Override
        public int advance(int target) {
            return next = target;
        }

        @Override
        public long cost() {
            return 0;
        }

        @Override
        public long longValue() {
            return next;
        }
    };
    IndexReaderStub stub = new IndexReaderStub(identityValues);
    stub.setElements(new String[maxDocs]);
    return stub;
}
Also used : NumericDocValues(org.apache.lucene.index.NumericDocValues) IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub)

Example 10 with IndexReaderStub

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

the class DocValuesCollectorTest method shouldNotSaveScoresForIndexProgressorWhenNotRequired.

@Test
void shouldNotSaveScoresForIndexProgressorWhenNotRequired() throws Exception {
    // given
    DocValuesCollector collector = new DocValuesCollector(false);
    IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
    // when
    collector.doSetNextReader(readerStub.getContext());
    collector.collect(1);
    // then
    AtomicReference<AcceptedEntity> ref = new AtomicReference<>();
    IndexProgressor.EntityValueClient client = new EntityValueClientWritingToReference(ref);
    IndexProgressor progressor = collector.getIndexProgressor("field", client);
    assertTrue(progressor.next());
    assertFalse(progressor.next());
    progressor.close();
    AcceptedEntity entity = ref.get();
    assertThat(entity.reference).isEqualTo(1L);
    assertTrue(Float.isNaN(entity.score));
}
Also used : IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) IndexProgressor(org.neo4j.kernel.api.index.IndexProgressor) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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