Package org.apache.lucene.util

Examples of org.apache.lucene.util.OpenBitSet


    int listSize = openBitSets.size();
    if ( listSize == 1 ) {
      return openBitSets.get( 0 );
    }
    //we need to copy the first OpenBitSet because BitSet is modified by .logicalOp
    OpenBitSet result = (OpenBitSet) openBitSets.get( 0 ).clone();
    for ( int i = 1; i < listSize; i++ ) {
      OpenBitSet openSet = openBitSets.get( i );
      result.intersect( openSet );
    }
    return result;
  }
View Full Code Here


    docIdBitSet = makeDocIdSetOnAgreedBits( iterators ); // before returning hold a copy as cache
    return docIdBitSet;
  }

  private DocIdSet makeDocIdSetOnAgreedBits(final DocIdSetIterator[] iterators) throws IOException {
    final OpenBitSet result = new OpenBitSet( maxDocNumber );
    final int numberOfIterators = iterators.length;

    int targetPosition = findFirstTargetPosition( iterators, result );

    if ( targetPosition == DocIdSetIterator.NO_MORE_DOCS ) {
      return DocIdSet.EMPTY_DOCIDSET;
    }

    // Each iterator can vote "ok" for the current target to
    // be reached; when all agree the bit is set.
    // if an iterator disagrees (it jumped longer), it's current position becomes the new targetPosition
    // for the others and he is considered "first" in the voting round (every iterator votes for himself ;-)

    int i = 0;
    int votes = 0; //could be smarter but would make the code even more complex for a minor optimization out of cycle.
    // enter main loop:
    while ( true ) {
      final DocIdSetIterator iterator = iterators[i];
      int position = targetPosition;
      if ( !iteratorAlreadyOnTargetPosition( targetPosition, iterator ) ) {
        position = iterator.advance( targetPosition );
      }
      if ( position == DocIdSetIterator.NO_MORE_DOCS ) {
        return result;
      } //exit condition
      if ( position == targetPosition ) {
        if ( ++votes == numberOfIterators ) {
          result.fastSet( position );
          votes = 0;
          targetPosition++;
        }
      }
      else {
View Full Code Here

    int listSize = openBitSets.size();
    if ( listSize == 1 ) {
      return openBitSets.get( 0 );
    }
    //we need to copy the first OpenBitSet because BitSet is modified by .logicalOp
    OpenBitSet result = (OpenBitSet) openBitSets.get( 0 ).clone();
    for ( int i=1; i<listSize; i++ ) {
      OpenBitSet openSet = openBitSets.get( i );
      result.intersect( openSet );
    }
    return result;
  }
View Full Code Here

    OpenBitSet dels;
    OpenBitSet oldDels = null;

    public FakeDeleteIndexReader(IndexReader in) {
      super(in);
      dels = new OpenBitSet(in.maxDoc());
      if (in.hasDeletions()) {
        oldDels = new OpenBitSet(in.maxDoc());
        for (int i = 0; i < in.maxDoc(); i++) {
          if (in.isDeleted(i)) oldDels.set(i);
        }
        dels.or(oldDels);
      }
View Full Code Here

     * Just removes our overlaid deletions - does not undelete the original
     * deletions.
     */
    @Override
    protected void doUndeleteAll() throws CorruptIndexException, IOException {
      dels = new OpenBitSet(in.maxDoc());
      if (oldDels != null) {
        dels.or(oldDels);
      }
    }
View Full Code Here

    w.close();
    IndexReader reader = IndexReader.open(rd, true);
   
    TermsFilter tf=new TermsFilter();
    tf.addTerm(new Term(fieldName,"19"));
    OpenBitSet bits = (OpenBitSet)tf.getDocIdSet(reader);
    assertEquals("Must match nothing", 0, bits.cardinality());

    tf.addTerm(new Term(fieldName,"20"));
    bits = (OpenBitSet)tf.getDocIdSet(reader);
    assertEquals("Must match 1", 1, bits.cardinality());
   
    tf.addTerm(new Term(fieldName,"10"));
    bits = (OpenBitSet)tf.getDocIdSet(reader);
    assertEquals("Must match 2", 2, bits.cardinality());
   
    tf.addTerm(new Term(fieldName,"00"));
    bits = (OpenBitSet)tf.getDocIdSet(reader);
    assertEquals("Must match 2", 2, bits.cardinality());
       
  }
View Full Code Here

      final IndexSearcher indexSearcher = newSearcher(indexReader);
      try {
        final Query phraseQuery = new SpanNearQuery(new SpanQuery[] {
            new SpanTermQuery(new Term(FIELD, "fox")),
            new SpanTermQuery(new Term(FIELD, "jumped")) }, 0, true);
        final OpenBitSet bitset = new OpenBitSet();
        indexSearcher.search(phraseQuery, new Collector() {
          private int baseDoc;

          @Override
          public boolean acceptsDocsOutOfOrder() {
            return true;
          }

          @Override
          public void collect(int i) throws IOException {
            bitset.set(this.baseDoc + i);
          }

          @Override
          public void setNextReader(IndexReader indexreader, int i)
              throws IOException {
            this.baseDoc = i;
          }

          @Override
          public void setScorer(org.apache.lucene.search.Scorer scorer)
              throws IOException {
            // Do Nothing
          }
        });
        assertEquals(1, bitset.cardinality());
        final Highlighter highlighter = new Highlighter(
            new SimpleHTMLFormatter(), new SimpleHTMLEncoder(),
            new QueryScorer(phraseQuery));
        for (int position = bitset.nextSetBit(0); position >= 0; position = bitset
            .nextSetBit(position + 1)) {
          assertEquals(0, position);
          final TokenStream tokenStream = TokenSources.getTokenStream(
              (TermPositionVector) indexReader.getTermFreqVector(position,
                  FIELD), false);
View Full Code Here

    int listSize = openBitSets.size();
    if ( listSize == 1 ) {
      return openBitSets.get( 0 );
    }
    //we need to copy the first OpenBitSet because BitSet is modified by .logicalOp
    OpenBitSet result = (OpenBitSet) openBitSets.get( 0 ).clone();
    for ( int i = 1; i < listSize; i++ ) {
      OpenBitSet openSet = openBitSets.get( i );
      result.intersect( openSet );
    }
    return result;
  }
View Full Code Here

    docIdBitSet = makeDocIdSetOnAgreedBits( iterators ); // before returning hold a copy as cache
    return docIdBitSet;
  }

  private DocIdSet makeDocIdSetOnAgreedBits(final DocIdSetIterator[] iterators) throws IOException {
    final OpenBitSet result = new OpenBitSet( maxDocNumber );
    final int numberOfIterators = iterators.length;

    int targetPosition = findFirstTargetPosition( iterators, result );

    if ( targetPosition == DocIdSetIterator.NO_MORE_DOCS ) {
      return EMPTY_DOCIDSET;
    }

    // Each iterator can vote "ok" for the current target to
    // be reached; when all agree the bit is set.
    // if an iterator disagrees (it jumped longer), it's current position becomes the new targetPosition
    // for the others and he is considered "first" in the voting round (every iterator votes for himself ;-)

    int i = 0;
    int votes = 0; //could be smarter but would make the code even more complex for a minor optimization out of cycle.
    // enter main loop:
    while ( true ) {
      final DocIdSetIterator iterator = iterators[i];
      int position = targetPosition;
      if ( !iteratorAlreadyOnTargetPosition( targetPosition, iterator ) ) {
        position = iterator.advance( targetPosition );
      }
      if ( position == DocIdSetIterator.NO_MORE_DOCS ) {
        return result;
      } //exit condition
      if ( position == targetPosition ) {
        if ( ++votes == numberOfIterators ) {
          result.fastSet( position );
          votes = 0;
          targetPosition++;
        }
      }
      else {
View Full Code Here

public class BitDocSet extends DocSetBase {
  final OpenBitSet bits;
  int size;    // number of docs in the set (cached for perf)

  public BitDocSet() {
    bits = new OpenBitSet();
  }
View Full Code Here

TOP

Related Classes of org.apache.lucene.util.OpenBitSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.