use of org.apache.lucene.util.FixedBitSet in project lucene-solr by apache.
the class TestBlockJoinSelector method testDocsWithValue.
public void testDocsWithValue() {
final BitSet parents = new FixedBitSet(20);
parents.set(0);
parents.set(5);
parents.set(6);
parents.set(10);
parents.set(15);
parents.set(19);
final BitSet children = new FixedBitSet(20);
children.set(2);
children.set(3);
children.set(4);
children.set(12);
children.set(17);
final BitSet childDocsWithValue = new FixedBitSet(20);
childDocsWithValue.set(2);
childDocsWithValue.set(3);
childDocsWithValue.set(4);
childDocsWithValue.set(8);
childDocsWithValue.set(16);
final Bits docsWithValue = BlockJoinSelector.wrap(childDocsWithValue, parents, children);
assertFalse(docsWithValue.get(0));
assertTrue(docsWithValue.get(5));
assertFalse(docsWithValue.get(6));
assertFalse(docsWithValue.get(10));
assertFalse(docsWithValue.get(15));
assertFalse(docsWithValue.get(19));
}
use of org.apache.lucene.util.FixedBitSet in project lucene-solr by apache.
the class TestBlockJoinSelector method testSortedSelector.
public void testSortedSelector() throws IOException {
final BitSet parents = new FixedBitSet(20);
parents.set(0);
parents.set(5);
parents.set(6);
parents.set(10);
parents.set(15);
parents.set(19);
final BitSet children = new FixedBitSet(20);
children.set(2);
children.set(3);
children.set(4);
children.set(12);
children.set(17);
final int[] ords = new int[20];
Arrays.fill(ords, -1);
ords[2] = 5;
ords[3] = 7;
ords[4] = 3;
ords[12] = 10;
ords[18] = 10;
final SortedDocValues mins = BlockJoinSelector.wrap(DocValues.singleton(new CannedSortedDocValues(ords)), BlockJoinSelector.Type.MIN, parents, children);
assertEquals(5, mins.nextDoc());
assertEquals(3, mins.ordValue());
assertEquals(15, mins.nextDoc());
assertEquals(10, mins.ordValue());
assertEquals(19, mins.nextDoc());
assertEquals(10, mins.ordValue());
assertEquals(NO_MORE_DOCS, mins.nextDoc());
final SortedDocValues maxs = BlockJoinSelector.wrap(DocValues.singleton(new CannedSortedDocValues(ords)), BlockJoinSelector.Type.MAX, parents, children);
assertEquals(5, maxs.nextDoc());
assertEquals(7, maxs.ordValue());
assertEquals(15, maxs.nextDoc());
assertEquals(10, maxs.ordValue());
assertEquals(19, maxs.nextDoc());
assertEquals(10, maxs.ordValue());
assertEquals(NO_MORE_DOCS, maxs.nextDoc());
}
use of org.apache.lucene.util.FixedBitSet in project lucene-solr by apache.
the class TestDocSet method doFilterTest.
public void doFilterTest(IndexReader reader) throws IOException {
IndexReaderContext topLevelContext = reader.getContext();
FixedBitSet bs = getRandomSet(reader.maxDoc(), rand.nextInt(reader.maxDoc() + 1));
DocSet a = new BitDocSet(bs);
DocSet b = getIntDocSet(bs);
Filter fa = a.getTopFilter();
Filter fb = b.getTopFilter();
/* top level filters are no longer supported
// test top-level
DocIdSet da = fa.getDocIdSet(topLevelContext);
DocIdSet db = fb.getDocIdSet(topLevelContext);
doTestIteratorEqual(da, db);
***/
DocIdSet da;
DocIdSet db;
List<LeafReaderContext> leaves = topLevelContext.leaves();
// first test in-sequence sub readers
for (LeafReaderContext readerContext : leaves) {
da = fa.getDocIdSet(readerContext, null);
db = fb.getDocIdSet(readerContext, null);
doTestIteratorEqual(da, db);
}
int nReaders = leaves.size();
// now test out-of-sequence sub readers
for (int i = 0; i < nReaders; i++) {
LeafReaderContext readerContext = leaves.get(rand.nextInt(nReaders));
da = fa.getDocIdSet(readerContext, null);
db = fb.getDocIdSet(readerContext, null);
doTestIteratorEqual(da, db);
}
}
use of org.apache.lucene.util.FixedBitSet in project lucene-solr by apache.
the class TestDocSet method getRandomDocSet.
public DocSet getRandomDocSet(int n, int maxDoc) {
FixedBitSet obs = new FixedBitSet(maxDoc);
int[] a = new int[n];
for (int i = 0; i < n; i++) {
for (; ; ) {
int idx = rand.nextInt(maxDoc);
if (obs.getAndSet(idx))
continue;
a[i] = idx;
break;
}
}
if (n <= smallSetCuttoff) {
if (smallSetType == 0) {
Arrays.sort(a);
return new SortedIntDocSet(a);
} else if (smallSetType == 1) {
Arrays.sort(a);
return loadfactor != 0 ? new HashDocSet(a, 0, n, 1 / loadfactor) : new HashDocSet(a, 0, n);
}
}
return new BitDocSet(obs, n);
}
use of org.apache.lucene.util.FixedBitSet in project lucene-solr by apache.
the class Lucene50LiveDocsFormat method readLiveDocs.
@Override
public Bits readLiveDocs(Directory dir, SegmentCommitInfo info, IOContext context) throws IOException {
long gen = info.getDelGen();
String name = IndexFileNames.fileNameFromGeneration(info.info.name, EXTENSION, gen);
final int length = info.info.maxDoc();
try (ChecksumIndexInput input = dir.openChecksumInput(name, context)) {
Throwable priorE = null;
try {
CodecUtil.checkIndexHeader(input, CODEC_NAME, VERSION_START, VERSION_CURRENT, info.info.getId(), Long.toString(gen, Character.MAX_RADIX));
long[] data = new long[FixedBitSet.bits2words(length)];
for (int i = 0; i < data.length; i++) {
data[i] = input.readLong();
}
FixedBitSet fbs = new FixedBitSet(data, length);
if (fbs.length() - fbs.cardinality() != info.getDelCount()) {
throw new CorruptIndexException("bits.deleted=" + (fbs.length() - fbs.cardinality()) + " info.delcount=" + info.getDelCount(), input);
}
return fbs;
} catch (Throwable exception) {
priorE = exception;
} finally {
CodecUtil.checkFooter(input, priorE);
}
}
throw new AssertionError();
}
Aggregations