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

The following examples show how to use org.apache.lucene.util.FixedBitSet#or() . 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: TestFilterLeafReader.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public NumericDocValues getNormValues(String field) throws IOException {
  NumericDocValues ndv = super.getNormValues(field);
  if (ndv == null) {
    return null;
  }
  FixedBitSet docsWithTerms = new FixedBitSet(maxDoc());
  TermsEnum termsEnum = terms(field).iterator();
  PostingsEnum postings = null;
  while (termsEnum.next() != null) {
    postings = termsEnum.postings(postings, PostingsEnum.NONE);
    docsWithTerms.or(postings);
  }
  return new FilterNumericDocValues(ndv) {
    @Override
    public long longValue() throws IOException {
      return docsWithTerms.get(docID()) ? super.longValue() : 0L;
    }
  };
}
 
Example 2
Source File: BitDocSet.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public DocSet union(DocSet other) {
  FixedBitSet newbits = bits.clone();
  if (other instanceof BitDocSet) {
    BitDocSet otherDocSet = (BitDocSet) other;
    newbits = FixedBitSet.ensureCapacity(newbits, otherDocSet.bits.length());
    newbits.or(otherDocSet.bits);
  } else {
    DocIterator iter = other.iterator();
    while (iter.hasNext()) {
      int doc = iter.nextDoc();
      newbits = FixedBitSet.ensureCapacity(newbits, doc);
      newbits.set(doc);
    }
  }
  return new BitDocSet(newbits);
}
 
Example 3
Source File: BitsFilter.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void or(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.or(b);
    }
}
 
Example 4
Source File: TestConjunctionDISI.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private static FixedBitSet clearRandomBits(FixedBitSet other) {
  final FixedBitSet set = new FixedBitSet(other.length());
  set.or(other);
  for (int i = 0; i < set.length(); ++i) {
    if (random().nextBoolean()) {
      set.clear(i);
    }
  }
  return set;
}
 
Example 5
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 6
Source File: SortedIntDocSet.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public DocSet union(DocSet other) {
  // TODO could be more efficient if both are SortedIntDocSet
  FixedBitSet otherBits = other.getFixedBitSet();
  FixedBitSet newbits = FixedBitSet.ensureCapacity(getFixedBitSetClone(), otherBits.length());
  newbits.or(otherBits);
  return new BitDocSet(newbits);
}
 
Example 7
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));
}
 
Example 8
Source File: BitDocSet.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void addAllTo(FixedBitSet target) {
  target.or(bits);
}