org.apache.solr.search
Class BitDocSet

java.lang.Object
  extended by org.apache.solr.search.BitDocSet
All Implemented Interfaces:
DocSet

public class BitDocSet
extends Object

BitDocSet represents an unordered set of Lucene Document Ids using a BitSet. A set bit represents inclusion in the set for that document.

Since:
solr 0.9
Version:
$Id: BitDocSet.java 1065312 2011-01-30 16:08:25Z rmuir $

Constructor Summary
BitDocSet()
           
BitDocSet(OpenBitSet bits)
          Construct a BitDocSet.
BitDocSet(OpenBitSet bits, int size)
          Construct a BitDocSet, and provides the number of set bits.
 
Method Summary
 void add(int doc)
          Adds the specified document if it is not currently in the DocSet (optional operation).
 void addUnique(int doc)
          Adds a document the caller knows is not currently in the DocSet (optional operation).
 DocSet andNot(DocSet other)
          Returns the documents in this set that are not in the other set.
 int andNotSize(DocSet other)
          Returns the number of documents in this set that are not in the other set.
 boolean equals(Object obj)
           
 boolean exists(int doc)
          Returns true if a document is in the DocSet.
 OpenBitSet getBits()
          Inefficient base implementation.
 Filter getTopFilter()
          Returns a Filter for use in Lucene search methods, assuming this DocSet was generated from the top-level MultiReader that the Lucene search methods will be invoked with.
 DocSet intersection(DocSet other)
          Returns the intersection of this set with another set.
 int intersectionSize(DocSet other)
          Returns the number of documents of the intersection of this set with another set.
 void invalidateSize()
          The number of set bits - size - is cached.
 DocIterator iterator()
          DocIterator using nextSetBit() public DocIterator iterator() { return new DocIterator() { int pos=bits.nextSetBit(0); public boolean hasNext() { return pos>=0; } public Integer next() { return nextDoc(); } public void remove() { bits.clear(pos); } public int nextDoc() { int old=pos; pos=bits.nextSetBit(old+1); return old; } public float score() { return 0.0f; } }; }
 long memSize()
          Returns the approximate amount of memory taken by this DocSet.
 int size()
          Returns the number of documents in the set.
 DocSet union(DocSet other)
          Returns the union of this set with another set.
 int unionSize(DocSet other)
          Returns the number of documents of the union of this set with another set.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BitDocSet

public BitDocSet()

BitDocSet

public BitDocSet(OpenBitSet bits)
Construct a BitDocSet. The capacity of the OpenBitSet should be at least maxDoc()


BitDocSet

public BitDocSet(OpenBitSet bits,
                 int size)
Construct a BitDocSet, and provides the number of set bits. The capacity of the OpenBitSet should be at least maxDoc()

Method Detail

iterator

public DocIterator iterator()
DocIterator using nextSetBit() public DocIterator iterator() { return new DocIterator() { int pos=bits.nextSetBit(0); public boolean hasNext() { return pos>=0; } public Integer next() { return nextDoc(); } public void remove() { bits.clear(pos); } public int nextDoc() { int old=pos; pos=bits.nextSetBit(old+1); return old; } public float score() { return 0.0f; } }; }


getBits

public OpenBitSet getBits()
Inefficient base implementation.

Specified by:
getBits in interface DocSet
Returns:
the internal OpenBitSet that should not be modified.
See Also:
getBits()

add

public void add(int doc)
Description copied from interface: DocSet
Adds the specified document if it is not currently in the DocSet (optional operation).

Specified by:
add in interface DocSet
See Also:
DocSet.addUnique(int)

addUnique

public void addUnique(int doc)
Description copied from interface: DocSet
Adds a document the caller knows is not currently in the DocSet (optional operation).

This method may be faster then add(doc) in some implementaions provided the caller is certain of the precondition.

Specified by:
addUnique in interface DocSet
See Also:
DocSet.add(int)

size

public int size()
Description copied from interface: DocSet
Returns the number of documents in the set.


invalidateSize

public void invalidateSize()
The number of set bits - size - is cached. If the bitset is changed externally, this method should be used to invalidate the previously cached size.


exists

public boolean exists(int doc)
Description copied from interface: DocSet
Returns true if a document is in the DocSet.


intersectionSize

public int intersectionSize(DocSet other)
Description copied from interface: DocSet
Returns the number of documents of the intersection of this set with another set. May be more efficient than actually creating the intersection and then getting it's size.

Specified by:
intersectionSize in interface DocSet

unionSize

public int unionSize(DocSet other)
Description copied from interface: DocSet
Returns the number of documents of the union of this set with another set. May be more efficient than actually creating the union and then getting it's size.

Specified by:
unionSize in interface DocSet

andNotSize

public int andNotSize(DocSet other)
Description copied from interface: DocSet
Returns the number of documents in this set that are not in the other set.

Specified by:
andNotSize in interface DocSet

andNot

public DocSet andNot(DocSet other)
Description copied from interface: DocSet
Returns the documents in this set that are not in the other set. Neither set is modified - a new DocSet is created and returned.

Specified by:
andNot in interface DocSet
Returns:
a DocSet representing this AND NOT other

union

public DocSet union(DocSet other)
Description copied from interface: DocSet
Returns the union of this set with another set. Neither set is modified - a new DocSet is created and returned.

Specified by:
union in interface DocSet
Returns:
a DocSet representing the union

memSize

public long memSize()
Description copied from interface: DocSet
Returns the approximate amount of memory taken by this DocSet. This is only an approximation and doesn't take into account java object overhead.

Returns:
the approximate memory consumption in bytes

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

intersection

public DocSet intersection(DocSet other)
Description copied from interface: DocSet
Returns the intersection of this set with another set. Neither set is modified - a new DocSet is created and returned.

Specified by:
intersection in interface DocSet
Returns:
a DocSet representing the intersection

getTopFilter

public Filter getTopFilter()
Description copied from interface: DocSet
Returns a Filter for use in Lucene search methods, assuming this DocSet was generated from the top-level MultiReader that the Lucene search methods will be invoked with.

Specified by:
getTopFilter in interface DocSet