Search in sources :

Example 6 with WritableIndexPartition

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

the class NodeRangeDocumentLabelScanStorageStrategyTest method shouldStoreAnyNodeIdInRange.

@Test
public void shouldStoreAnyNodeIdInRange() throws Exception {
    for (int i = 0, max = 1 << format.bitmapFormat().shift; i < max; i++) {
        // given
        IndexWriter indexWriter = mock(IndexWriter.class);
        WritableIndexPartition partition = newIndexPartitionMock(indexWriter);
        WritableDatabaseLabelScanIndex index = buildLuceneIndex(partition);
        LabelScanWriter writer = new PartitionedLuceneLabelScanWriter(index, format);
        // when
        writer.write(labelChanges(i, labels(), labels(7)));
        writer.close();
        // then
        Document document = new Document();
        format.addRangeValuesField(document, 0);
        format.addLabelAndSearchFields(document, 7, new Bitmap(1L << i));
        verify(indexWriter).updateDocument(eq(format.rangeTerm(0)), match(document));
    }
}
Also used : Bitmap(org.neo4j.kernel.api.impl.labelscan.bitmaps.Bitmap) WritableDatabaseLabelScanIndex(org.neo4j.kernel.api.impl.labelscan.WritableDatabaseLabelScanIndex) IndexWriter(org.apache.lucene.index.IndexWriter) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) WritableIndexPartition(org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition) Document(org.apache.lucene.document.Document) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) LabelScanWriter(org.neo4j.kernel.api.labelscan.LabelScanWriter) Test(org.junit.Test)

Example 7 with WritableIndexPartition

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

the class NodeRangeDocumentLabelScanStorageStrategyTest method newIndexPartitionMock.

private WritableIndexPartition newIndexPartitionMock(IndexWriter indexWriter, Document... documents) throws IOException {
    WritableIndexPartition partition = mock(WritableIndexPartition.class);
    PartitionSearcher partitionSearcher = mock(PartitionSearcher.class);
    when(partition.acquireSearcher()).thenReturn(partitionSearcher);
    when(partition.getIndexWriter()).thenReturn(indexWriter);
    IndexSearcher searcher = mock(IndexSearcher.class);
    when(partitionSearcher.getIndexSearcher()).thenReturn(searcher);
    for (int i = 0; i < documents.length; i++) {
        int docId = i;
        doAnswer(invocation -> {
            FirstHitCollector collector = (FirstHitCollector) invocation.getArguments()[1];
            try {
                collector.collect(docId);
            } catch (CollectionTerminatedException swallow) {
            }
            return null;
        }).when(searcher).search(eq(new TermQuery(format.rangeTerm(documents[i]))), any(FirstHitCollector.class));
        when(searcher.doc(i)).thenReturn(documents[i]);
    }
    return partition;
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TermQuery(org.apache.lucene.search.TermQuery) PartitionSearcher(org.neo4j.kernel.api.impl.index.partition.PartitionSearcher) CollectionTerminatedException(org.apache.lucene.search.CollectionTerminatedException) WritableIndexPartition(org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition) FirstHitCollector(org.neo4j.kernel.api.impl.index.collector.FirstHitCollector)

Example 8 with WritableIndexPartition

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

the class NonUniqueDatabaseIndexSamplerTest method samplingOfLargeNumericValues.

@Test
public void samplingOfLargeNumericValues() throws Exception {
    try (RAMDirectory dir = new RAMDirectory();
        WritableIndexPartition indexPartition = new WritableIndexPartition(new File("testPartition"), dir, IndexWriterConfigs.standard())) {
        insertDocument(indexPartition, 1, Long.MAX_VALUE);
        insertDocument(indexPartition, 2, Integer.MAX_VALUE);
        indexPartition.maybeRefreshBlocking();
        try (PartitionSearcher searcher = indexPartition.acquireSearcher()) {
            NonUniqueLuceneIndexSampler sampler = new NonUniqueLuceneIndexSampler(searcher.getIndexSearcher(), taskControl.newInstance(), new IndexSamplingConfig(Config.empty()));
            assertEquals(new IndexSample(2, 2, 2), sampler.sampleIndex());
        }
    }
}
Also used : IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) IndexSample(org.neo4j.storageengine.api.schema.IndexSample) PartitionSearcher(org.neo4j.kernel.api.impl.index.partition.PartitionSearcher) WritableIndexPartition(org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition) File(java.io.File) RAMDirectory(org.apache.lucene.store.RAMDirectory) Test(org.junit.Test)

Aggregations

WritableIndexPartition (org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition)8 Test (org.junit.Test)7 IndexWriter (org.apache.lucene.index.IndexWriter)6 WritableDatabaseLabelScanIndex (org.neo4j.kernel.api.impl.labelscan.WritableDatabaseLabelScanIndex)6 PartitionedLuceneLabelScanWriter (org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter)6 LabelScanWriter (org.neo4j.kernel.api.labelscan.LabelScanWriter)6 Document (org.apache.lucene.document.Document)5 PartitionSearcher (org.neo4j.kernel.api.impl.index.partition.PartitionSearcher)3 IndexSearcher (org.apache.lucene.search.IndexSearcher)2 TermQuery (org.apache.lucene.search.TermQuery)2 Bitmap (org.neo4j.kernel.api.impl.labelscan.bitmaps.Bitmap)2 File (java.io.File)1 CollectionTerminatedException (org.apache.lucene.search.CollectionTerminatedException)1 RAMDirectory (org.apache.lucene.store.RAMDirectory)1 FirstHitCollector (org.neo4j.kernel.api.impl.index.collector.FirstHitCollector)1 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig)1 IndexSample (org.neo4j.storageengine.api.schema.IndexSample)1