Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-2736

Wrong implementation of DocIdSetIterator.advance

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.2, 4.0-ALPHA
    • 3.2, 4.0-ALPHA
    • core/search
    • None
    • New, Patch Available

    Description

      Implementations of DocIdSetIterator behave differently when advanced is called. Taking the following test for OpenBitSet, DocIdBitSet and SortedVIntList only SortedVIntList passes the test:

      org.apache.lucene.search.TestDocIdSet.java
      ...
      	public void testAdvanceWithOpenBitSet() throws IOException {
      		DocIdSet idSet = new OpenBitSet( new long[] { 1121 }, 1 );  // bits 0, 5, 6, 10
      		assertAdvance( idSet );
      	}
      
      	public void testAdvanceDocIdBitSet() throws IOException {
      		BitSet bitSet = new BitSet();
      		bitSet.set( 0 );
      		bitSet.set( 5 );
      		bitSet.set( 6 );
      		bitSet.set( 10 );
      		DocIdSet idSet = new DocIdBitSet(bitSet);
      		assertAdvance( idSet );
      	}
      
      	public void testAdvanceWithSortedVIntList() throws IOException {
      		DocIdSet idSet = new SortedVIntList( 0, 5, 6, 10 );
      		assertAdvance( idSet );
      	}	
      
      	private void assertAdvance(DocIdSet idSet) throws IOException {
      		DocIdSetIterator iter = idSet.iterator();
      		int docId = iter.nextDoc();
      		assertEquals( "First doc id should be 0", 0, docId );
      
      		docId = iter.nextDoc();
      		assertEquals( "Second doc id should be 5", 5, docId );
      
      		docId = iter.advance( 5 );
      		assertEquals( "Advancing iterator should return the next doc id", 6, docId );
      	}
      

      The javadoc for advance says:

      Advances to the first beyond the current whose document number is greater than or equal to target.

      This seems to indicate that SortedVIntList behaves correctly, whereas the other two don't.
      Just looking at the DocIdBitSet implementation advance is implemented as:

      bitSet.nextSetBit(target);
      

      where the docs of nextSetBit say:

      Returns the index of the first bit that is set to true that occurs on or after the specified starting index

      Attachments

        1. LUCENE-2736.patch
          1 kB
          Shai Erera

        Activity

          People

            shaie Shai Erera
            hardy Hardy Ferentschik
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: