com.sun.labs.minion.retrieval
Class ArrayGroup

java.lang.Object
  extended by com.sun.labs.minion.retrieval.ArrayGroup
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
NegativeGroup, ScoredGroup

public class ArrayGroup
extends java.lang.Object
implements java.lang.Cloneable

A container for the sets of arrays that are generated during document retrieval operations. This class implements a strict boolean set of documents, i.e., documents in such a set do not have any scores associated with them.


Nested Class Summary
 class ArrayGroup.DocIterator
          A class that provides an iterator for the documents in this group.
 
Field Summary
protected  int[] docs
          The documents in the set.
protected static java.lang.String logTag
           
protected  DiskPartition part
          The partition that generated this set.
protected  PassageStore[] pass
          Passages for each field.
protected  java.util.List queryTerms
          The query terms that generated this set.
protected  int size
          The size of the current set, that is the number of documents that it contains.
protected  ScoreModifier sm
           
protected  int width
          The width of the original query, in terms.
 
Constructor Summary
protected ArrayGroup()
           
protected ArrayGroup(ArrayGroup ag)
          Creates a group that shares a set of documents with another group.
  ArrayGroup(DiskPartition part, int[] docs, int l)
          Creates an array group with the specified array of document IDs.
  ArrayGroup(int n)
          Creates a group that can hold the given number of documents.
  ArrayGroup(int[] docs, int l)
          Creates an array group with the specified array of document IDs.
  ArrayGroup(PostingsIterator pi)
          Creates an array group from the given postings iterator.
 
Method Summary
 void addDoc(int docID)
          Adds a document to the group.
protected  void addPassage(int field, int[] newPass, float penalty)
          Adds a passage to the passages stored for the given field.
protected  void addPassage(int pos, int field, int[] newPass, float penalty)
          Adds a passage to the passages stored for the given field for the document stored at the given position.
protected  ArrayGroup agIntersect(ArrayGroup ag)
           
protected  ArrayGroup agUnion(ArrayGroup ag)
          Unions a statically-typed array group with the current group.
 java.lang.Object clone()
          Clones this group.
protected  ArrayGroup destructiveIntersect(ArrayGroup ag)
           
 ArrayGroup destructiveIntersect(PostingsIterator pi)
          Intersects a postings iterator with this group, destructively.
 boolean equals(java.lang.Object o)
          Tests two array groups for equality.
 int getDoc(int i)
          Gets the docId at a particular index
 int[] getDocs()
          Gets the documents making up this array group, as an array sized to fit.
 ArrayGroup getNegative()
          Returns a negative version of this array group.
 DiskPartition getPartition()
          Gets the partition that generated this group.
 java.util.Map getPassages(int doc)
           
 ScoredGroup getScored()
          Gets a scored version of this array group.
 int getSize()
          Returns the size of this set.
 ArrayGroup getStrict()
          Gets a strict version of this array group, which just returns this group.
protected  void init(ArrayGroup ag)
          Initializes this group with data from another group.
protected  void init(PostingsIterator pi)
          Re-initializes the group with the contents of the given postings iterator.
 ArrayGroup intersect(ArrayGroup ag)
          Dispatches the intersect operator to the appropriate method by downcasting the Object to the proper subtype.
 ArrayGroup intersect(NegativeGroup ag)
           
 ArrayGroup intersect(QueryTerm t)
          Intersects the documents generated by the term with the ones in this group.
 ArrayGroup intersect(ScoredGroup ag)
           
 ArrayGroup.DocIterator iterator()
          Gets an iterator that will return each document in the set.
 ArrayGroup mult(float m)
          Applies a multiplier to an array group, returning a new group.
 ArrayGroup normalize()
          Normalizes this group.
 void removeDeleted()
          Removes deleted documents from the results set, modifying the set in the process.
 void removeDeleted(ReadableBuffer del)
          Removes deleted documents from the results set, modifying the set in the process.
protected  void resize(int n)
          Resizes the group so that it can hold the given number of documents.
 void retain(int[] ids)
          Retain only the documents with the given ids
 void setDoc(int i, int docId)
          Sets the docId at a particular index
 void setPartition(DiskPartition part)
          Sets the partitoin for this group.
protected  void setScoreModifier(ScoreModifier sm)
           
 void setSize(int newSize)
          Sets the size of this set.
 java.lang.String toString()
           
 ArrayGroup union(ArrayGroup ag)
          Unions another group with this group.
protected  ArrayGroup union(ArrayGroup ag, PostingsIterator pi)
          Unions a postings iterator with this group, placing the results in the given group.
 ArrayGroup union(NegativeGroup ag)
          Unions a negative group with this group, returning a negative group.
 ArrayGroup union(QueryTerm t)
          Unions the documents generated by the term with the ones in this group.
 ArrayGroup union(ScoredGroup ag)
          Unions a scored group with this group, returning a new scored group.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

docs

protected int[] docs
The documents in the set. Elements of this array may be set to a value less than 0, indicating a position where a document was removed during processing.


width

protected int width
The width of the original query, in terms. Used to compute where the passages are in the pass array.


size

protected int size
The size of the current set, that is the number of documents that it contains.


pass

protected PassageStore[] pass
Passages for each field.


part

protected DiskPartition part
The partition that generated this set.


queryTerms

protected java.util.List queryTerms
The query terms that generated this set.


sm

protected ScoreModifier sm

logTag

protected static java.lang.String logTag
Constructor Detail

ArrayGroup

protected ArrayGroup()

ArrayGroup

public ArrayGroup(int n)
Creates a group that can hold the given number of documents.

Parameters:
n - The number of documents that the group must be able to hold.

ArrayGroup

public ArrayGroup(int[] docs,
                  int l)
Creates an array group with the specified array of document IDs.


ArrayGroup

public ArrayGroup(DiskPartition part,
                  int[] docs,
                  int l)
Creates an array group with the specified array of document IDs.


ArrayGroup

public ArrayGroup(PostingsIterator pi)
Creates an array group from the given postings iterator.


ArrayGroup

protected ArrayGroup(ArrayGroup ag)
Creates a group that shares a set of documents with another group.

Parameters:
ag - The group to share data with.
Method Detail

init

protected void init(ArrayGroup ag)
Initializes this group with data from another group. The data will be shared as much as possible in order to avoid copying.

Parameters:
ag - The group to share data with.

init

protected void init(PostingsIterator pi)
Re-initializes the group with the contents of the given postings iterator. To be used by others only in extremis (e.g., when unioning thousands of saved field terms), since this is destructive.

Parameters:
pi - The iterator to use.

resize

protected void resize(int n)
Resizes the group so that it can hold the given number of documents.

Parameters:
n - The number of documents that the group must be able to hold.

getNegative

public ArrayGroup getNegative()
Returns a negative version of this array group. The data will not be copied into the new group, rather it will share the data with the old group. This is so that we don't need to clone large arrays.

Returns:
A negative group containing the same documents as this group.

getStrict

public ArrayGroup getStrict()
Gets a strict version of this array group, which just returns this group.

Returns:
A strict group containing the same documents as this group.

getScored

public ScoredGroup getScored()
Gets a scored version of this array group. The data will not be copied into the new group, rather it will share the data with the old group. This is so that we don't need to clone large arrays.

Returns:
A scored group containing the same documents as this group. If this group is a scored group, the documents in the new group will have the same scores, otherwise all of the scores will be 1.

normalize

public ArrayGroup normalize()
Normalizes this group.


getSize

public int getSize()
Returns the size of this set.


setSize

public void setSize(int newSize)
Sets the size of this set. Only do this if you know what you're doing.

Parameters:
newSize - the new size

getDocs

public int[] getDocs()
Gets the documents making up this array group, as an array sized to fit.


getDoc

public int getDoc(int i)
Gets the docId at a particular index


setDoc

public void setDoc(int i,
                   int docId)
Sets the docId at a particular index


addDoc

public void addDoc(int docID)
Adds a document to the group.


union

public ArrayGroup union(QueryTerm t)
Unions the documents generated by the term with the ones in this group. Note that if the limit on the document set size has been surpassed, we will only consider modifying the scores for documents that are already in the set.

Returns:
The result of unioning the current term with this set. The static type of the result is determined by a combination of the types of the groups being combined and the current query status.

intersect

public ArrayGroup intersect(QueryTerm t)
Intersects the documents generated by the term with the ones in this group. A new group is returned.

Parameters:
t - The term to intersect with the current set.
Returns:
The result of intersecting the given term with this set.

removeDeleted

public void removeDeleted()
Removes deleted documents from the results set, modifying the set in the process.


removeDeleted

public void removeDeleted(ReadableBuffer del)
Removes deleted documents from the results set, modifying the set in the process.


retain

public void retain(int[] ids)
Retain only the documents with the given ids

Parameters:
ids - document ids to keep

destructiveIntersect

public ArrayGroup destructiveIntersect(PostingsIterator pi)
Intersects a postings iterator with this group, destructively.


union

public ArrayGroup union(ArrayGroup ag)
Unions another group with this group.

Parameters:
ag - The group to union with this group.
Returns:
The result of unioning the given group with this group. The static type of the return value will depend on the type of ag.

agUnion

protected ArrayGroup agUnion(ArrayGroup ag)
Unions a statically-typed array group with the current group. This should be used only for array groups that have the static type ArrayGroup!


union

public ArrayGroup union(ScoredGroup ag)
Unions a scored group with this group, returning a new scored group.

Parameters:
ag - The group to union with this group.
Returns:
an instance of ScoredGroup that contains scores for the documents that have them.

union

protected ArrayGroup union(ArrayGroup ag,
                           PostingsIterator pi)
Unions a postings iterator with this group, placing the results in the given group. This is to be used only in extremis, since it's destructive to the given group.

Parameters:
ag - The group to put the results in. May need resizing.
pi - The postings iterator to union.
Returns:
ag

union

public ArrayGroup union(NegativeGroup ag)
Unions a negative group with this group, returning a negative group.

Parameters:
ag - The negative group to union with this group.

intersect

public ArrayGroup intersect(ArrayGroup ag)
Dispatches the intersect operator to the appropriate method by downcasting the Object to the proper subtype. The given object must be an instance of ArrayGroup or QueryTerm.

Returns:
The result of intersecting the given element with the current group. The static type of the result is determined by a combination of the types of the groups being combined and the current query status.
Throws:
java.lang.ClassCastException - if the given object is not an instance of ArrayGroup or QueryTerm.

agIntersect

protected ArrayGroup agIntersect(ArrayGroup ag)

destructiveIntersect

protected ArrayGroup destructiveIntersect(ArrayGroup ag)

intersect

public ArrayGroup intersect(ScoredGroup ag)

intersect

public ArrayGroup intersect(NegativeGroup ag)

mult

public ArrayGroup mult(float m)
Applies a multiplier to an array group, returning a new group. This will only affect scored groups, but a query may apply a multiplier to any group.

Parameters:
m - The multiplier to apply.
Returns:
A group where the multiplier has been applied. The current group is not affected.

setScoreModifier

protected void setScoreModifier(ScoreModifier sm)

addPassage

protected void addPassage(int field,
                          int[] newPass,
                          float penalty)
Adds a passage to the passages stored for the given field. The passage is added to the document currently at the end of the set.


addPassage

protected void addPassage(int pos,
                          int field,
                          int[] newPass,
                          float penalty)
Adds a passage to the passages stored for the given field for the document stored at the given position.


getPassages

public java.util.Map getPassages(int doc)

getPartition

public DiskPartition getPartition()
Gets the partition that generated this group.


setPartition

public void setPartition(DiskPartition part)
Sets the partitoin for this group.


iterator

public ArrayGroup.DocIterator iterator()
Gets an iterator that will return each document in the set.


clone

public java.lang.Object clone()
Clones this group.

Overrides:
clone in class java.lang.Object
Returns:
a clone of this group. We will clone the internal arrays.

equals

public boolean equals(java.lang.Object o)
Tests two array groups for equality. Two groups are equal if they contain exactly the same set of documents.

Overrides:
equals in class java.lang.Object
Returns:
true if the groups contain the same documents, false otherwise.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object