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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations