Search in sources :

Example 1 with IndexReaderStub

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

the class PageOfRangesIteratorTest method shouldReadPagesOfDocumentsFromSearcher.

@Test
public void shouldReadPagesOfDocumentsFromSearcher() throws Exception {
    final int labelId = 7;
    final int pageSize = 2;
    // given
    Query query = mock(Query.class);
    IndexSearcher searcher = mock(IndexSearcher.class);
    NumericDocValues rangeNDV = mock(NumericDocValues.class);
    when(rangeNDV.get(11)).thenReturn(0x1L);
    when(rangeNDV.get(16)).thenReturn(0x2L);
    when(rangeNDV.get(37)).thenReturn(0x3L);
    NumericDocValues labelNDV = mock(NumericDocValues.class);
    when(labelNDV.get(11)).thenReturn(0x01L);
    when(labelNDV.get(16)).thenReturn(0x03L);
    when(labelNDV.get(37)).thenReturn(0x30L);
    Map<String, NumericDocValues> docValues = MapUtil.genericMap("range", rangeNDV, "7", labelNDV);
    IndexReaderStub reader = new IndexReaderStub(docValues);
    reader.setElements(new String[] { "11", "16", "37" });
    final LeafReaderContext context = reader.getContext();
    doAnswer(invocation -> {
        DocValuesCollector collector = (DocValuesCollector) invocation.getArguments()[1];
        collector.doSetNextReader(context);
        collector.collect(11);
        collector.collect(16);
        collector.collect(37);
        return null;
    }).when(searcher).search(same(query), any(DocValuesCollector.class));
    PrimitiveLongIterator iterator = concat(new PageOfRangesIterator(format, searcher, pageSize, query, Occur.MUST, labelId));
    // when
    List<Long> longs = PrimitiveLongCollections.asList(iterator);
    // then
    assertEquals(asList(/*doc1:*/
    1L << format.bitmapFormat().shift, /*doc2:*/
    2L << format.bitmapFormat().shift, (2L << format.bitmapFormat().shift) + 1, /*doc3:*/
    (3L << format.bitmapFormat().shift) + 4, (3L << format.bitmapFormat().shift) + 5), longs);
    verify(searcher, times(1)).search(same(query), any(DocValuesCollector.class));
    verify(rangeNDV, times(6)).get(anyInt());
    verify(labelNDV, times(3)).get(anyInt());
    verifyNoMoreInteractions(searcher);
    verifyNoMoreInteractions(labelNDV);
    verifyNoMoreInteractions(rangeNDV);
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) NumericDocValues(org.apache.lucene.index.NumericDocValues) Query(org.apache.lucene.search.Query) IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) DocValuesCollector(org.neo4j.kernel.api.impl.index.collector.DocValuesCollector) PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) Test(org.junit.Test)

Example 2 with IndexReaderStub

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

the class DocValuesCollectorTest method shouldReturnEmptyIteratorWhenNoHits.

@Test
public void shouldReturnEmptyIteratorWhenNoHits() throws Exception {
    // given
    DocValuesCollector collector = new DocValuesCollector(false);
    IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
    // when
    collector.doSetNextReader(readerStub.getContext());
    // then
    IndexHits<Document> indexHits = collector.getIndexHits(null);
    assertEquals(0, indexHits.size());
    assertEquals(Float.NaN, indexHits.currentScore(), 0.0f);
    assertFalse(indexHits.hasNext());
}
Also used : IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) Document(org.apache.lucene.document.Document) Test(org.junit.Test)

Example 3 with IndexReaderStub

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

the class DocValuesCollectorTest method shouldReturnIndexHitsOrderedByRelevance.

@Test
public void shouldReturnIndexHitsOrderedByRelevance() 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
    IndexHits<Document> indexHits = collector.getIndexHits(Sort.RELEVANCE);
    assertEquals(2, indexHits.size());
    assertEquals("2", indexHits.next().get("id"));
    assertEquals(2.0f, indexHits.currentScore(), 0.0f);
    assertEquals("1", indexHits.next().get("id"));
    assertEquals(1.0f, indexHits.currentScore(), 0.0f);
    assertFalse(indexHits.hasNext());
}
Also used : IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) Document(org.apache.lucene.document.Document) Test(org.junit.Test)

Example 4 with IndexReaderStub

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

the class DocValuesCollectorTest method shouldReadDocValuesInIndexOrder.

@Test
public void shouldReadDocValuesInIndexOrder() throws Exception {
    // given
    DocValuesCollector collector = new DocValuesCollector(false);
    IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
    // when
    collector.doSetNextReader(readerStub.getContext());
    collector.collect(1);
    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 5 with IndexReaderStub

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

the class DocValuesCollectorTest method shouldReturnDocValuesInIndexOrderWhenNoSortIsGiven.

@Test
public void shouldReturnDocValuesInIndexOrderWhenNoSortIsGiven() throws Exception {
    // given
    DocValuesCollector collector = new DocValuesCollector(false);
    IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
    // when
    collector.doSetNextReader(readerStub.getContext());
    collector.collect(1);
    collector.collect(2);
    // then
    PrimitiveLongIterator valuesIterator = collector.getSortedValuesIterator("id", null);
    assertEquals(1, valuesIterator.next());
    assertEquals(2, valuesIterator.next());
    assertFalse(valuesIterator.hasNext());
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) Test(org.junit.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