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