Java Code Examples for org.apache.lucene.util.BitSet#set()

The following examples show how to use org.apache.lucene.util.BitSet#set() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestBlockJoinSelector.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 2
Source File: TestBlockJoinSelector.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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, toIter(children));
  assertEquals(5, nextDoc(mins,5));
  assertEquals(3, mins.ordValue());
  assertEquals(15, nextDoc(mins,15));
  assertEquals(10, mins.ordValue());
  assertNoMoreDoc(mins, 20);

  final SortedDocValues maxs = BlockJoinSelector.wrap(DocValues.singleton(new CannedSortedDocValues(ords)), BlockJoinSelector.Type.MAX, parents, toIter(children));
  assertEquals(5, nextDoc(maxs,5));
  assertEquals(7, maxs.ordValue());
  assertEquals(15, nextDoc(maxs,15));
  assertEquals(10, maxs.ordValue());
  assertNoMoreDoc( maxs,20);
}
 
Example 3
Source File: TestIndexedDISI.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Nightly
public void testEmptyBlocks() throws IOException {
  final int B = 65536;
  int maxDoc = B*11;
  BitSet set = new SparseFixedBitSet(maxDoc);
  // block 0: EMPTY
  set.set(B+5); // block 1: SPARSE
  // block 2: EMPTY
  // block 3: EMPTY
  set.set(B*4+5); // block 4: SPARSE

  for (int i = 0 ; i < B ; i++) {
    set.set(B*6+i); // block 6: ALL
  }
  for (int i = 0 ; i < B ; i+=3) {
    set.set(B*7+i); // block 7: DENSE
  }
  for (int i = 0 ; i < B ; i++) {
    if (i != 32768) {
      set.set(B*8 + i); // block 8: DENSE (all-1)
    }
  }
  // block 9-11: EMPTY

  try (Directory dir = newDirectory()) {
    doTestAllSingleJump(set, dir);
  }

  // Change the first block to DENSE to see if jump-tables sets to position 0
  set.set(0);
  try (Directory dir = newDirectory()) {
    doTestAllSingleJump(set, dir);
  }
}
 
Example 4
Source File: TestIndexedDISI.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testLastEmptyBlocks() throws IOException {
  final int B = 65536;
  int maxDoc = B*3;
  BitSet set = new SparseFixedBitSet(maxDoc);
  for (int docID = 0 ; docID < B*2 ; docID++) { // first 2 blocks are ALL
    set.set(docID);
  }
  // Last block is EMPTY

  try (Directory dir = newDirectory()) {
    doTestAllSingleJump(set, dir);
    assertAdvanceBeyondEnd(set, dir);
  }
}
 
Example 5
Source File: TestIndexedDISI.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private BitSet createSetWithRandomBlocks(int blockCount) {
  final int B = 65536;
  BitSet set = new SparseFixedBitSet(blockCount * B);
  for (int block = 0; block < blockCount; block++) {
    switch (random().nextInt(4)) {
      case 0: { // EMPTY
        break;
      }
      case 1: { // ALL
        for (int docID = block* B; docID < (block+1)* B; docID++) {
          set.set(docID);
        }
        break;
      }
      case 2: { // SPARSE ( < 4096 )
        for (int docID = block* B; docID < (block+1)* B; docID += 101) {
          set.set(docID);
        }
        break;
      }
      case 3: { // DENSE ( >= 4096 )
        for (int docID = block* B; docID < (block+1)* B; docID += 3) {
          set.set(docID);
        }
        break;
      }
      default: throw new IllegalStateException("Modulo logic error: there should only be 4 possibilities");
    }
  }
  return set;
}
 
Example 6
Source File: TestIndexedDISI.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testOneDoc() throws IOException {
  int maxDoc = TestUtil.nextInt(random(), 1, 100000);
  BitSet set = new SparseFixedBitSet(maxDoc);
  set.set(random().nextInt(maxDoc));
  try (Directory dir = newDirectory()) {
    doTest(set, dir);
  }
}
 
Example 7
Source File: TestIndexedDISI.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testTwoDocs() throws IOException {
  int maxDoc = TestUtil.nextInt(random(), 1, 100000);
  BitSet set = new SparseFixedBitSet(maxDoc);
  set.set(random().nextInt(maxDoc));
  set.set(random().nextInt(maxDoc));
  try (Directory dir = newDirectory()) {
    doTest(set, dir);
  }
}
 
Example 8
Source File: TestIndexedDISI.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testHalfFull() throws IOException {
  int maxDoc = TestUtil.nextInt(random(), 1, 100000);
  BitSet set = new SparseFixedBitSet(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);
  }
}
 
Example 9
Source File: TestBlockJoinSelector.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void testNumericSelector() throws Exception {
  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 long[] longs = new long[20];
  final BitSet docsWithValue = new FixedBitSet(20);
  docsWithValue.set(2);
  longs[2] = 5;
  docsWithValue.set(3);
  longs[3] = 7;
  docsWithValue.set(4);
  longs[4] = 3;
  docsWithValue.set(12);
  longs[12] = 10;
  docsWithValue.set(18);
  longs[18] = 10;

  final NumericDocValues mins = BlockJoinSelector.wrap(DocValues.singleton(new CannedNumericDocValues(longs, docsWithValue)), BlockJoinSelector.Type.MIN, parents, toIter(children));
  assertEquals(5, nextDoc(mins,5));
  assertEquals(3, mins.longValue());
  assertEquals(15, nextDoc(mins,15));
  assertEquals(10, mins.longValue());
  assertNoMoreDoc(mins, 20);

  final NumericDocValues maxs = BlockJoinSelector.wrap(DocValues.singleton(new CannedNumericDocValues(longs, docsWithValue)), BlockJoinSelector.Type.MAX, parents, toIter(children));
  assertEquals(5, nextDoc(maxs, 5));
  assertEquals(7, maxs.longValue());
  assertEquals(15, nextDoc(maxs, 15));
  assertEquals(10, maxs.longValue());
  assertNoMoreDoc(maxs, 20);
}