Search in sources :

Example 26 with LongSupplier

use of java.util.function.LongSupplier in project lucene-solr by apache.

the class BaseNormsFormatTestCase method testNCommonBig.

/**
   * a more thorough n-common that tests all low bpv
   */
@Nightly
public void testNCommonBig() throws Exception {
    final int iterations = atLeast(1);
    final Random r = random();
    for (int i = 0; i < iterations; ++i) {
        // 16 is 4 bpv, the max before we jump to 8bpv
        for (int n = 2; n < 16; ++n) {
            final int N = n;
            final long[] commonValues = new long[N];
            for (int j = 0; j < N; ++j) {
                commonValues[j] = TestUtil.nextLong(r, Byte.MIN_VALUE, Byte.MAX_VALUE);
            }
            final int numOtherValues = TestUtil.nextInt(r, 2, 256 - N);
            final long[] otherValues = new long[numOtherValues];
            for (int j = 0; j < numOtherValues; ++j) {
                otherValues[j] = TestUtil.nextLong(r, Byte.MIN_VALUE, Byte.MAX_VALUE);
            }
            doTestNormsVersusDocValues(1, new LongSupplier() {

                @Override
                public long getAsLong() {
                    return r.nextInt(100) == 0 ? otherValues[r.nextInt(numOtherValues - 1)] : commonValues[r.nextInt(N - 1)];
                }
            });
        }
    }
}
Also used : Random(java.util.Random) LongSupplier(java.util.function.LongSupplier)

Example 27 with LongSupplier

use of java.util.function.LongSupplier in project lucene-solr by apache.

the class BaseNormsFormatTestCase method testSparseOutliers2.

public void testSparseOutliers2() throws Exception {
    assumeTrue("Requires sparse norms support", codecSupportsSparsity());
    int iterations = atLeast(1);
    final Random r = random();
    for (int i = 0; i < iterations; i++) {
        final long commonValue = TestUtil.nextLong(r, Byte.MIN_VALUE, Byte.MAX_VALUE);
        final long uncommonValue = TestUtil.nextLong(r, Byte.MIN_VALUE, Byte.MAX_VALUE);
        doTestNormsVersusDocValues(random().nextDouble(), new LongSupplier() {

            @Override
            public long getAsLong() {
                return r.nextInt(100) == 0 ? uncommonValue : commonValue;
            }
        });
    }
}
Also used : Random(java.util.Random) LongSupplier(java.util.function.LongSupplier)

Example 28 with LongSupplier

use of java.util.function.LongSupplier in project lucene-solr by apache.

the class BaseNormsFormatTestCase method testOutliers2.

public void testOutliers2() throws Exception {
    int iterations = atLeast(1);
    final Random r = random();
    for (int i = 0; i < iterations; i++) {
        final long commonValue = TestUtil.nextLong(r, Byte.MIN_VALUE, Byte.MAX_VALUE);
        final long uncommonValue = TestUtil.nextLong(r, Byte.MIN_VALUE, Byte.MAX_VALUE);
        doTestNormsVersusDocValues(1, new LongSupplier() {

            @Override
            public long getAsLong() {
                return r.nextInt(100) == 0 ? uncommonValue : commonValue;
            }
        });
    }
}
Also used : Random(java.util.Random) LongSupplier(java.util.function.LongSupplier)

Example 29 with LongSupplier

use of java.util.function.LongSupplier in project lucene-solr by apache.

the class BaseNormsFormatTestCase method testSparseFullLongRange.

public void testSparseFullLongRange() throws Exception {
    assumeTrue("Requires sparse norms support", codecSupportsSparsity());
    int iterations = atLeast(1);
    final Random r = random();
    for (int i = 0; i < iterations; i++) {
        doTestNormsVersusDocValues(random().nextDouble(), new LongSupplier() {

            @Override
            public long getAsLong() {
                int thingToDo = r.nextInt(3);
                switch(thingToDo) {
                    case 0:
                        return Long.MIN_VALUE;
                    case 1:
                        return Long.MAX_VALUE;
                    default:
                        return TestUtil.nextLong(r, Long.MIN_VALUE, Long.MAX_VALUE);
                }
            }
        });
    }
}
Also used : Random(java.util.Random) LongSupplier(java.util.function.LongSupplier)

Example 30 with LongSupplier

use of java.util.function.LongSupplier in project lucene-solr by apache.

the class TestLucene70DocValuesFormat method doTestSparseNumericBlocksOfVariousBitsPerValue.

private void doTestSparseNumericBlocksOfVariousBitsPerValue(double density) throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
    conf.setMaxBufferedDocs(atLeast(Lucene70DocValuesFormat.NUMERIC_BLOCK_SIZE));
    conf.setRAMBufferSizeMB(-1);
    conf.setMergePolicy(newLogMergePolicy(random().nextBoolean()));
    IndexWriter writer = new IndexWriter(dir, conf);
    Document doc = new Document();
    Field storedField = newStringField("stored", "", Field.Store.YES);
    Field dvField = new NumericDocValuesField("dv", 0);
    doc.add(storedField);
    doc.add(dvField);
    final int numDocs = atLeast(Lucene70DocValuesFormat.NUMERIC_BLOCK_SIZE * 3);
    final LongSupplier longs = blocksOfVariousBPV();
    for (int i = 0; i < numDocs; i++) {
        if (random().nextDouble() > density) {
            writer.addDocument(new Document());
            continue;
        }
        long value = longs.getAsLong();
        storedField.setStringValue(Long.toString(value));
        dvField.setLongValue(value);
        writer.addDocument(doc);
    }
    writer.forceMerge(1);
    writer.close();
    // compare
    DirectoryReader ir = DirectoryReader.open(dir);
    TestUtil.checkReader(ir);
    for (LeafReaderContext context : ir.leaves()) {
        LeafReader r = context.reader();
        NumericDocValues docValues = DocValues.getNumeric(r, "dv");
        docValues.nextDoc();
        for (int i = 0; i < r.maxDoc(); i++) {
            String storedValue = r.document(i).get("stored");
            if (storedValue == null) {
                assertTrue(docValues.docID() > i);
            } else {
                assertEquals(i, docValues.docID());
                assertEquals(Long.parseLong(storedValue), docValues.longValue());
                docValues.nextDoc();
            }
        }
        assertEquals(DocIdSetIterator.NO_MORE_DOCS, docValues.docID());
    }
    ir.close();
    dir.close();
}
Also used : SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) NumericDocValues(org.apache.lucene.index.NumericDocValues) LeafReader(org.apache.lucene.index.LeafReader) DirectoryReader(org.apache.lucene.index.DirectoryReader) Document(org.apache.lucene.document.Document) IndexableField(org.apache.lucene.index.IndexableField) SortedNumericDocValuesField(org.apache.lucene.document.SortedNumericDocValuesField) StoredField(org.apache.lucene.document.StoredField) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) SortedSetDocValuesField(org.apache.lucene.document.SortedSetDocValuesField) BinaryDocValuesField(org.apache.lucene.document.BinaryDocValuesField) SortedDocValuesField(org.apache.lucene.document.SortedDocValuesField) StringField(org.apache.lucene.document.StringField) Field(org.apache.lucene.document.Field) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) SortedNumericDocValuesField(org.apache.lucene.document.SortedNumericDocValuesField) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) IndexWriter(org.apache.lucene.index.IndexWriter) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) LongSupplier(java.util.function.LongSupplier) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Aggregations

LongSupplier (java.util.function.LongSupplier)31 Random (java.util.Random)21 StoredField (org.apache.lucene.document.StoredField)3 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)2 Document (org.apache.lucene.document.Document)2 Field (org.apache.lucene.document.Field)2 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)2 SortedNumericDocValuesField (org.apache.lucene.document.SortedNumericDocValuesField)2 DirectoryReader (org.apache.lucene.index.DirectoryReader)2 IndexWriter (org.apache.lucene.index.IndexWriter)2 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)2 IndexableField (org.apache.lucene.index.IndexableField)2 LeafReader (org.apache.lucene.index.LeafReader)2 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)2 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)2 SortedNumericDocValues (org.apache.lucene.index.SortedNumericDocValues)2 Directory (org.apache.lucene.store.Directory)2 Test (org.junit.Test)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1