Search in sources :

Example 21 with IndexReaderStub

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);
}
Also used : IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) IndexProgressor(org.neo4j.kernel.api.index.IndexProgressor) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 22 with IndexReaderStub

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());
}
Also used : IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) LongIterator(org.eclipse.collections.api.iterator.LongIterator) Test(org.junit.jupiter.api.Test)

Example 23 with IndexReaderStub

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());
}
Also used : IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator) Test(org.junit.jupiter.api.Test)

Example 24 with IndexReaderStub

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());
}
Also used : IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator) Test(org.junit.jupiter.api.Test)

Example 25 with IndexReaderStub

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());
}
Also used : IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) Terms(org.apache.lucene.index.Terms) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) 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