use of org.neo4j.kernel.api.impl.index.IndexReaderStub in project neo4j by neo4j.
the class DocValuesCollectorTest method shouldSaveScoresForIndexProgressorWhenRequired.
@Test
void shouldSaveScoresForIndexProgressorWhenRequired() throws Exception {
// given
DocValuesCollector collector = new DocValuesCollector(true);
IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
float score = 13.42f;
// when
collector.doSetNextReader(readerStub.getContext());
collector.setScorer(constantScorer(score));
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);
assertThat(entity.score).isEqualTo(score);
}
use of org.neo4j.kernel.api.impl.index.IndexReaderStub in project neo4j by neo4j.
the class DocValuesCollectorTest method shouldSilentlyMergeSegmentsWhenReturnDocValuesInOrder.
@Test
void shouldSilentlyMergeSegmentsWhenReturnDocValuesInOrder() 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.doSetNextReader(readerStub.getContext());
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());
}
use of org.neo4j.kernel.api.impl.index.IndexReaderStub in project neo4j by neo4j.
the class DocValuesCollectorTest method shouldCollectAllHitsPerSegment.
@Test
void shouldCollectAllHitsPerSegment() throws Exception {
// given
DocValuesCollector collector = new DocValuesCollector();
IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
// when
collector.doSetNextReader(readerStub.getContext());
collector.collect(1);
collector.collect(3);
collector.collect(5);
collector.collect(9);
// then
assertEquals(4, collector.getTotalHits());
List<DocValuesCollector.MatchingDocs> allMatchingDocs = collector.getMatchingDocs();
assertEquals(1, allMatchingDocs.size());
DocValuesCollector.MatchingDocs matchingDocs = allMatchingDocs.get(0);
assertSame(readerStub.getContext(), matchingDocs.context);
assertEquals(4, matchingDocs.totalHits);
DocIdSetIterator idIterator = matchingDocs.docIdSet;
assertEquals(1, idIterator.nextDoc());
assertEquals(3, idIterator.nextDoc());
assertEquals(5, idIterator.nextDoc());
assertEquals(9, idIterator.nextDoc());
assertEquals(DocIdSetIterator.NO_MORE_DOCS, idIterator.nextDoc());
}
use of org.neo4j.kernel.api.impl.index.IndexReaderStub in project neo4j by neo4j.
the class DocValuesCollectorTest method shouldCollectOneMatchingDocsPerSegment.
@Test
void shouldCollectOneMatchingDocsPerSegment() throws Exception {
// given
DocValuesCollector collector = new DocValuesCollector();
IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
// when
collector.doSetNextReader(readerStub.getContext());
collector.collect(1);
collector.collect(3);
collector.doSetNextReader(readerStub.getContext());
collector.collect(5);
collector.collect(9);
// then
assertEquals(4, collector.getTotalHits());
List<DocValuesCollector.MatchingDocs> allMatchingDocs = collector.getMatchingDocs();
assertEquals(2, allMatchingDocs.size());
DocValuesCollector.MatchingDocs matchingDocs = allMatchingDocs.get(0);
assertSame(readerStub.getContext(), matchingDocs.context);
assertEquals(2, matchingDocs.totalHits);
DocIdSetIterator idIterator = matchingDocs.docIdSet;
assertEquals(1, idIterator.nextDoc());
assertEquals(3, idIterator.nextDoc());
assertEquals(DocIdSetIterator.NO_MORE_DOCS, idIterator.nextDoc());
matchingDocs = allMatchingDocs.get(1);
assertSame(readerStub.getContext(), matchingDocs.context);
assertEquals(2, matchingDocs.totalHits);
idIterator = matchingDocs.docIdSet;
assertEquals(5, idIterator.nextDoc());
assertEquals(9, idIterator.nextDoc());
assertEquals(DocIdSetIterator.NO_MORE_DOCS, idIterator.nextDoc());
}
use of org.neo4j.kernel.api.impl.index.IndexReaderStub in project neo4j by neo4j.
the class NonUniqueDatabaseIndexSamplerTest method nonUniqueSamplingCancel.
@Test
void nonUniqueSamplingCancel() throws IOException {
Terms terms = getTerms("test", 1);
Map<String, Terms> fieldTermsMap = MapUtil.genericMap("0string", terms, "id", terms, "0string", terms);
IndexReaderStub indexReader = new IndexReaderStub(new SamplingFields(fieldTermsMap));
when(indexSearcher.getIndexReader()).thenReturn(indexReader);
NonUniqueLuceneIndexSampler luceneIndexSampler = createSampler();
taskControl.cancel();
IndexNotFoundKernelException notFoundKernelException = assertThrows(IndexNotFoundKernelException.class, () -> luceneIndexSampler.sampleIndex(NULL));
assertEquals("Index dropped while sampling.", notFoundKernelException.getMessage());
}
Aggregations