Search in sources :

Example 51 with FixedBitSet

use of org.apache.lucene.util.FixedBitSet in project lucene-solr by apache.

the class TestIndexedDISI method testHalfFull.

public void testHalfFull() throws IOException {
    int maxDoc = TestUtil.nextInt(random(), 1, 100000);
    FixedBitSet set = new FixedBitSet(maxDoc);
    for (int i = random().nextInt(2); i < maxDoc; i += TestUtil.nextInt(random(), 1, 3)) {
        set.set(i);
    }
    try (Directory dir = newDirectory()) {
        doTest(set, dir);
    }
}
Also used : FixedBitSet(org.apache.lucene.util.FixedBitSet) Directory(org.apache.lucene.store.Directory)

Example 52 with FixedBitSet

use of org.apache.lucene.util.FixedBitSet in project lucene-solr by apache.

the class TestIndexedDISI method testDocRange.

public void testDocRange() throws IOException {
    try (Directory dir = newDirectory()) {
        for (int iter = 0; iter < 10; ++iter) {
            int maxDoc = TestUtil.nextInt(random(), 1, 1000000);
            FixedBitSet set = new FixedBitSet(maxDoc);
            final int start = random().nextInt(maxDoc);
            final int end = TestUtil.nextInt(random(), start + 1, maxDoc);
            set.set(start, end);
            doTest(set, dir);
        }
    }
}
Also used : FixedBitSet(org.apache.lucene.util.FixedBitSet) Directory(org.apache.lucene.store.Directory)

Example 53 with FixedBitSet

use of org.apache.lucene.util.FixedBitSet in project lucene-solr by apache.

the class TestIndexedDISI method testSparseDenseBoundary.

public void testSparseDenseBoundary() throws IOException {
    try (Directory dir = newDirectory()) {
        FixedBitSet set = new FixedBitSet(200000);
        int start = 65536 + random().nextInt(100);
        // we set MAX_ARRAY_LENGTH bits so the encoding will be sparse
        set.set(start, start + IndexedDISI.MAX_ARRAY_LENGTH);
        long length;
        try (IndexOutput out = dir.createOutput("sparse", IOContext.DEFAULT)) {
            IndexedDISI.writeBitSet(new BitSetIterator(set, IndexedDISI.MAX_ARRAY_LENGTH), out);
            length = out.getFilePointer();
        }
        try (IndexInput in = dir.openInput("sparse", IOContext.DEFAULT)) {
            IndexedDISI disi = new IndexedDISI(in, 0L, length, IndexedDISI.MAX_ARRAY_LENGTH);
            assertEquals(start, disi.nextDoc());
            assertEquals(IndexedDISI.Method.SPARSE, disi.method);
        }
        doTest(set, dir);
        // now we set one more bit so the encoding will be dense
        set.set(start + IndexedDISI.MAX_ARRAY_LENGTH + random().nextInt(100));
        try (IndexOutput out = dir.createOutput("bar", IOContext.DEFAULT)) {
            IndexedDISI.writeBitSet(new BitSetIterator(set, IndexedDISI.MAX_ARRAY_LENGTH + 1), out);
            length = out.getFilePointer();
        }
        try (IndexInput in = dir.openInput("bar", IOContext.DEFAULT)) {
            IndexedDISI disi = new IndexedDISI(in, 0L, length, IndexedDISI.MAX_ARRAY_LENGTH + 1);
            assertEquals(start, disi.nextDoc());
            assertEquals(IndexedDISI.Method.DENSE, disi.method);
        }
        doTest(set, dir);
    }
}
Also used : BitSetIterator(org.apache.lucene.util.BitSetIterator) FixedBitSet(org.apache.lucene.util.FixedBitSet) IndexInput(org.apache.lucene.store.IndexInput) IndexOutput(org.apache.lucene.store.IndexOutput) Directory(org.apache.lucene.store.Directory)

Example 54 with FixedBitSet

use of org.apache.lucene.util.FixedBitSet in project lucene-solr by apache.

the class TestIndexedDISI method testFewMissingDocs.

public void testFewMissingDocs() throws IOException {
    try (Directory dir = newDirectory()) {
        for (int iter = 0; iter < 100; ++iter) {
            int maxDoc = TestUtil.nextInt(random(), 1, 100000);
            FixedBitSet set = new FixedBitSet(maxDoc);
            set.set(0, maxDoc);
            final int numMissingDocs = TestUtil.nextInt(random(), 2, 1000);
            for (int i = 0; i < numMissingDocs; ++i) {
                set.clear(random().nextInt(maxDoc));
            }
            doTest(set, dir);
        }
    }
}
Also used : FixedBitSet(org.apache.lucene.util.FixedBitSet) Directory(org.apache.lucene.store.Directory)

Example 55 with FixedBitSet

use of org.apache.lucene.util.FixedBitSet in project lucene-solr by apache.

the class TestIndexedDISI method doTestRandom.

private void doTestRandom(Directory dir) throws IOException {
    List<Integer> docs = new ArrayList<>();
    final int maxStep = TestUtil.nextInt(random(), 1, 1 << TestUtil.nextInt(random(), 2, 20));
    final int numDocs = TestUtil.nextInt(random(), 1, Math.min(100000, Integer.MAX_VALUE / maxStep));
    for (int doc = -1, i = 0; i < numDocs; ++i) {
        doc += TestUtil.nextInt(random(), 1, maxStep);
        docs.add(doc);
    }
    final int maxDoc = docs.get(docs.size() - 1) + TestUtil.nextInt(random(), 1, 100);
    FixedBitSet set = new FixedBitSet(maxDoc);
    for (int doc : docs) {
        set.set(doc);
    }
    doTest(set, dir);
}
Also used : FixedBitSet(org.apache.lucene.util.FixedBitSet) ArrayList(java.util.ArrayList)

Aggregations

FixedBitSet (org.apache.lucene.util.FixedBitSet)162 Term (org.apache.lucene.index.Term)27 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)26 Directory (org.apache.lucene.store.Directory)25 BytesRef (org.apache.lucene.util.BytesRef)22 IOException (java.io.IOException)19 Document (org.apache.lucene.document.Document)17 ArrayList (java.util.ArrayList)15 Query (org.apache.lucene.search.Query)15 NumericDocValues (org.apache.lucene.index.NumericDocValues)14 BitDocIdSet (org.apache.lucene.util.BitDocIdSet)13 Bits (org.apache.lucene.util.Bits)13 LeafReader (org.apache.lucene.index.LeafReader)12 IndexSearcher (org.apache.lucene.search.IndexSearcher)12 TermQuery (org.apache.lucene.search.TermQuery)12 IndexReader (org.apache.lucene.index.IndexReader)11 HashSet (java.util.HashSet)10 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)10 DocIterator (org.apache.solr.search.DocIterator)10 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)9