Search in sources :

Example 11 with IndexReaderStub

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

the class DocValuesCollectorTest method shouldReturnDocValuesInRelevanceOrder.

@Test
void shouldReturnDocValuesInRelevanceOrder() throws Exception {
    // given
    DocValuesCollector collector = new DocValuesCollector(true);
    IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
    // when
    collector.doSetNextReader(readerStub.getContext());
    collector.setScorer(constantScorer(1.0f));
    collector.collect(1);
    collector.setScorer(constantScorer(2.0f));
    collector.collect(2);
    // then
    LongIterator valuesIterator = collector.getValuesSortedByRelevance("id");
    assertEquals(2, valuesIterator.next());
    assertEquals(1, valuesIterator.next());
    assertFalse(valuesIterator.hasNext());
}
Also used : IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) LongIterator(org.eclipse.collections.api.iterator.LongIterator) Test(org.junit.jupiter.api.Test)

Example 12 with IndexReaderStub

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

the class DocValuesCollectorTest method shouldNotSaveScoresWhenNotRequired.

@Test
void shouldNotSaveScoresWhenNotRequired() throws Exception {
    // given
    DocValuesCollector collector = new DocValuesCollector(false);
    IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
    // when
    collector.doSetNextReader(readerStub.getContext());
    collector.collect(1);
    // then
    DocValuesCollector.MatchingDocs matchingDocs = collector.getMatchingDocs().get(0);
    assertNull(matchingDocs.scores);
}
Also used : IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) Test(org.junit.jupiter.api.Test)

Example 13 with IndexReaderStub

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

the class DocValuesCollectorTest method shouldSaveScoresWhenRequired.

@Test
void shouldSaveScoresWhenRequired() throws Exception {
    // given
    DocValuesCollector collector = new DocValuesCollector(true);
    IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
    // when
    collector.doSetNextReader(readerStub.getContext());
    collector.setScorer(constantScorer(13.42f));
    collector.collect(1);
    // then
    DocValuesCollector.MatchingDocs matchingDocs = collector.getMatchingDocs().get(0);
    assertArrayEquals(new float[] { 13.42f }, matchingDocs.scores, 0.001f);
}
Also used : IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) Test(org.junit.jupiter.api.Test)

Example 14 with IndexReaderStub

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

the class DocValuesCollectorTest method shouldSaveScoresInADenseArray.

@Test
void shouldSaveScoresInADenseArray() throws Exception {
    // given
    DocValuesCollector collector = new DocValuesCollector(true);
    IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
    // when
    collector.doSetNextReader(readerStub.getContext());
    collector.setScorer(constantScorer(1.0f));
    collector.collect(1);
    collector.setScorer(constantScorer(41.0f));
    collector.collect(41);
    // then
    DocValuesCollector.MatchingDocs matchingDocs = collector.getMatchingDocs().get(0);
    assertArrayEquals(new float[] { 1.0f, 41.0f }, matchingDocs.scores, 0.001f);
}
Also used : IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) Test(org.junit.jupiter.api.Test)

Example 15 with IndexReaderStub

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

the class DocValuesCollectorTest method shouldReturnEmptyIteratorWhenNoDocValuesInOrder.

@Test
void shouldReturnEmptyIteratorWhenNoDocValuesInOrder() throws Exception {
    // given
    DocValuesCollector collector = new DocValuesCollector(false);
    IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
    // when
    collector.doSetNextReader(readerStub.getContext());
    // then
    LongIterator valuesIterator = collector.getValuesSortedByRelevance("id");
    assertFalse(valuesIterator.hasNext());
}
Also used : IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) LongIterator(org.eclipse.collections.api.iterator.LongIterator) 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