Java Code Examples for org.apache.lucene.util.FixedBitSet#and()

The following examples show how to use org.apache.lucene.util.FixedBitSet#and() . 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: BitsFilter.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void and(BitsFilter bitsFilter)
{
    List<FixedBitSet> andSets = bitsFilter.bitSets;
    for(int i=0; i<bitSets.size(); i++)
    {
        FixedBitSet a = bitSets.get(i);
        FixedBitSet b = andSets.get(i);
        a.and(b);
    }
}
 
Example 2
Source File: TestConjunctionDISI.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private static FixedBitSet intersect(FixedBitSet[] bitSets) {
  final FixedBitSet intersection = new FixedBitSet(bitSets[0].length());
  intersection.or(bitSets[0]);
  for (int i = 1; i < bitSets.length; ++i) {
    intersection.and(bitSets[i]);
  }
  return intersection;
}
 
Example 3
Source File: TestScorerPerf.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
FixedBitSet addClause(FixedBitSet[] sets, BooleanQuery.Builder bq, FixedBitSet result) {
  final FixedBitSet rnd = sets[random().nextInt(sets.length)];
  Query q = new BitSetQuery(rnd);
  bq.add(q, BooleanClause.Occur.MUST);
  if (validate) {
    if (result==null) result = rnd.clone();
    else result.and(rnd);
  }
  return result;
}
 
Example 4
Source File: SolrIndexSplitter.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
  return new ConstantScoreWeight(this, boost) {

    @Override
    public Scorer scorer(LeafReaderContext context) throws IOException {
      RTimerTree t = timings.sub("findDocsToDelete");
      t.resume();
      FixedBitSet set = findDocsToDelete(context);
      t.pause();
      if (log.isInfoEnabled()) {
        log.info("### partition={}, leaf={}, maxDoc={}, numDels={}, setLen={}, setCard={}"
        , partition, context, context.reader().maxDoc()
        ,context.reader().numDeletedDocs(), set.length(), set.cardinality());
      }
      Bits liveDocs = context.reader().getLiveDocs();
      if (liveDocs != null) {
        // check that we don't delete already deleted docs
        FixedBitSet dels = FixedBitSet.copyOf(liveDocs);
        dels.flip(0, dels.length());
        dels.and(set);
        if (dels.cardinality() > 0) {
          log.error("### INVALID DELS {}", dels.cardinality());
        }
      }
      return new ConstantScoreScorer(this, score(), scoreMode, new BitSetIterator(set, set.length()));
    }

    @Override
    public boolean isCacheable(LeafReaderContext ctx) {
      return false;
    }

    @Override
    public String toString() {
      return "weight(shardSplittingQuery,part" + partition + ")";
    }
  };
}
 
Example 5
Source File: BitDocSet.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public DocSet intersection(DocSet other) {
  // intersection is overloaded in the smaller DocSets to be more
  // efficient, so dispatch off of it instead.
  if (!(other instanceof BitDocSet)) {
    return other.intersection(this);
  }

  // Default... handle with bitsets.
  FixedBitSet newbits = getFixedBitSetClone();
  newbits.and(other.getFixedBitSet());
  return new BitDocSet(newbits);
}
 
Example 6
Source File: TestDocSet.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected void doSingle(int maxSize) {
  int sz = rand.nextInt(maxSize+1);
  int sz2 = rand.nextInt(maxSize);
  FixedBitSet bs1 = getRandomSet(sz, rand.nextInt(sz+1));
  FixedBitSet bs2 = getRandomSet(sz, rand.nextInt(sz2+1));

  DocSet a1 = new BitDocSet(bs1);
  DocSet a2 = new BitDocSet(bs2);
  DocSet b1 = getDocSet(bs1);
  DocSet b2 = getDocSet(bs2);

  checkEqual(bs1,b1);
  checkEqual(bs2,b2);

  iter(a1,b1);
  iter(a2,b2);

  collect(a1, maxSize);
  collect(a2, maxSize);

  FixedBitSet a_and = bs1.clone(); a_and.and(bs2);
  FixedBitSet a_or = bs1.clone(); a_or.or(bs2);
  // FixedBitSet a_xor = bs1.clone(); a_xor.xor(bs2);
  FixedBitSet a_andn = bs1.clone(); a_andn.andNot(bs2);

  checkEqual(a_and, b1.intersection(b2));
  checkEqual(a_or, b1.union(b2));
  checkEqual(a_andn, b1.andNot(b2));

  assertEquals(a_and.cardinality(), b1.intersectionSize(b2));
  assertEquals(a_or.cardinality(), b1.unionSize(b2));
  assertEquals(a_andn.cardinality(), b1.andNotSize(b2));
}