Java Code Examples for org.apache.lucene.util.BitSetIterator#nextDoc()

The following examples show how to use org.apache.lucene.util.BitSetIterator#nextDoc() . 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: TestIndexedDISI.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void assertAdvanceBeyondEnd(BitSet set, Directory dir) throws IOException {
  final int cardinality = set.cardinality();
  final byte denseRankPower = 9; // Not tested here so fixed to isolate factors
  long length;
  int jumpTableentryCount;
  try (IndexOutput out = dir.createOutput("bar", IOContext.DEFAULT)) {
    jumpTableentryCount = IndexedDISI.writeBitSet(new BitSetIterator(set, cardinality), out, denseRankPower);
  }

  try (IndexInput in = dir.openInput("bar", IOContext.DEFAULT)) {
    BitSetIterator disi2 = new BitSetIterator(set, cardinality);
    int doc = disi2.docID();
    int index = 0;
    while (doc < cardinality) {
      doc = disi2.nextDoc();
      index++;
    }

    IndexedDISI disi = new IndexedDISI(in, 0L, in.length(), jumpTableentryCount, denseRankPower, cardinality);
    // Advance 1 docID beyond end
    assertFalse("There should be no set bit beyond the valid docID range", disi.advanceExact(set.length()));
    disi.advance(doc); // Should be the special docID signifyin NO_MORE_DOCS from the BitSetIterator
    assertEquals("The index when advancing beyond the last defined docID should be correct",
        index, disi.index()+1); // disi.index()+1 as the while-loop also counts the NO_MORE_DOCS
  }
}
 
Example 2
Source File: TestIndexedDISI.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void assertAdvanceExactRandomized(IndexedDISI disi, BitSetIterator disi2, int disi2length, int step)
    throws IOException {
  int index = -1;
  Random random = random();
  for (int target = 0; target < disi2length; ) {
    target += TestUtil.nextInt(random, 0, step);
    int doc = disi2.docID();
    while (doc < target) {
      doc = disi2.nextDoc();
      index++;
    }

    boolean exists = disi.advanceExact(target);
    assertEquals(doc == target, exists);
    if (exists) {
      assertEquals(index, disi.index());
    } else if (random.nextBoolean()) {
      assertEquals(doc, disi.nextDoc());
      // This is a bit strange when doc == NO_MORE_DOCS as the index overcounts in the disi2 while-loop
      assertEquals(index, disi.index());
      target = doc;
    }
  }
}
 
Example 3
Source File: TestIndexedDISI.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void assertAdvanceEquality(IndexedDISI disi, BitSetIterator disi2, int step) throws IOException {
  int index = -1;
  while (true) {
    int target = disi2.docID() + step;
    int doc;
    do {
      doc = disi2.nextDoc();
      index++;
    } while (doc < target);
    assertEquals(doc, disi.advance(target));
    if (doc == DocIdSetIterator.NO_MORE_DOCS) {
      break;
    }
    assertEquals("Expected equality using step " + step + " at docID " + doc, index, disi.index());
  }
}
 
Example 4
Source File: TestIndexedDISI.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void assertSingleStepEquality(IndexedDISI disi, BitSetIterator disi2) throws IOException {
  int i = 0;
  for (int doc = disi2.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = disi2.nextDoc()) {
    assertEquals(doc, disi.nextDoc());
    assertEquals(i++, disi.index());
  }
  assertEquals(DocIdSetIterator.NO_MORE_DOCS, disi.nextDoc());
}
 
Example 5
Source File: TestDocSet.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public DocSet getIntDocSet(FixedBitSet bs) {
  int[] docs = new int[bs.cardinality()];
  BitSetIterator iter = new BitSetIterator(bs, 0);
  for (int i=0; i<docs.length; i++) {
    docs[i] = iter.nextDoc();
  }
  return new SortedIntDocSet(docs);
}
 
Example 6
Source File: TestDocSet.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public DocSlice getDocSlice(FixedBitSet bs) {
  int len = bs.cardinality();
  int[] arr = new int[len+5];
  arr[0]=10; arr[1]=20; arr[2]=30; arr[arr.length-1]=1; arr[arr.length-2]=2;
  int offset = 3;
  int end = offset + len;

  BitSetIterator iter = new BitSetIterator(bs, 0);
  // put in opposite order... DocLists are not ordered.
  for (int i=end-1; i>=offset; i--) {
    arr[i] = iter.nextDoc();
  }

  return new DocSlice(offset, len, arr, null, len*2, 100.0f, TotalHits.Relation.EQUAL_TO);
}