org.cdlib.xtf.textEngine.facet
Class GroupCounts

Object
  extended by GroupCounts

public class GroupCounts
extends Object

Maintains an ongoing count of groups and how many document hits were found in each group.

Author:
Martin Haye

Nested Class Summary
static interface GroupCounts.DocHitMaker
           
static interface GroupCounts.HitQueueMaker
           
 
Field Summary
private  int[] count
           
private  int curMark
           
private  GroupData data
           
private  PriorityQueue[] hitQueue
           
private  GroupCounts.HitQueueMaker hitQueueMaker
           
private  int[] mark
           
private  int[] maxDocs
           
private  boolean prepMode
           
private  float[] score
           
private  int[] selection
           
private static int SORT_BY_MAX_DOC_SCORE
           
private static int SORT_BY_REVERSE_VALUE
           
private static int SORT_BY_TOTAL_DOCS
           
private static int SORT_BY_VALUE
           
private  int[] sortedChild
           
private  int[] sortedSibling
           
private  FacetSpec spec
           
private  int[] startDoc
           
 
Constructor Summary
GroupCounts(GroupData groupData, FacetSpec spec, GroupCounts.HitQueueMaker hitQueueMaker)
          Construct an object with all counts at zero
 
Method Summary
 void addDoc(GroupCounts.DocHitMaker docHitMaker)
          Add a document hit to the counts
private  void buildDocHits(int group, ResultGroup resultGroup)
          Construct the array of doc hits for the hit group.
 ResultGroup buildResultGroup(int parent)
           
 int child(int group)
          Get the first child of the given group, in properly sorted order
private static int compare(float x, float y)
          Compare two floats for sorting purposes
private static int compare(int x, int y)
          Compare two ints for sorting purposes
private  int compare(int g1, int g2, int sortKind)
          Compare two groups for sorting purposes.
private  void conservativePrep()
          Gather data about which groups to gather DocHits for.
private  int countDescendants(int group)
          Utility function to count the group and all of its descendants
 void gatherDocs(int group, int startDoc, int maxDocs)
          Called by GroupSelector to mark groups to receive documents
 ResultFacet getResult()
          Retrieve the result facet with its groupings.
 boolean isSelected(int group)
          Find out whether the given group is selected
 String name(int group)
          Get the name of a specific group
 int nDocHits(int group)
          Find out the number of doc hits for the given group
 int nGroups()
          Get the total number of groups
 boolean nondefaultSort()
          Called by GroupSelector to find out if the ordering is non-default
 int parent(int group)
          Get the parent of the given group
 float score(int group)
          Find out the score of the given group
 void selectGroup(int group)
          Called by GroupSelector to select a given group
 boolean shouldInclude(int group)
          Called by GroupSelector to find out if it should include a given group
 int sibling(int group)
          Get the next sibling of the given group, in properly sorted order
private  void sortAndSelect()
          Called during the prep phase for dynamic groups, and in the result building phase for static groups.
private  void sortChildren(int parent, int sortKind)
           
private  void sortGroups()
          Re-sort the hierarchy according to the facet spec, and store the new child/sibling relationships.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

private GroupData data

spec

private FacetSpec spec

hitQueueMaker

private GroupCounts.HitQueueMaker hitQueueMaker

prepMode

private boolean prepMode

count

private int[] count

score

private float[] score

mark

private int[] mark

selection

private int[] selection

startDoc

private int[] startDoc

maxDocs

private int[] maxDocs

hitQueue

private PriorityQueue[] hitQueue

sortedChild

private int[] sortedChild

sortedSibling

private int[] sortedSibling

curMark

private int curMark

SORT_BY_VALUE

private static final int SORT_BY_VALUE
See Also:
Constant Field Values

SORT_BY_REVERSE_VALUE

private static final int SORT_BY_REVERSE_VALUE
See Also:
Constant Field Values

SORT_BY_TOTAL_DOCS

private static final int SORT_BY_TOTAL_DOCS
See Also:
Constant Field Values

SORT_BY_MAX_DOC_SCORE

private static final int SORT_BY_MAX_DOC_SCORE
See Also:
Constant Field Values
Constructor Detail

GroupCounts

public GroupCounts(GroupData groupData,
                   FacetSpec spec,
                   GroupCounts.HitQueueMaker hitQueueMaker)
Construct an object with all counts at zero

Method Detail

conservativePrep

private void conservativePrep()
Gather data about which groups to gather DocHits for.


selectGroup

public final void selectGroup(int group)
Called by GroupSelector to select a given group


gatherDocs

public final void gatherDocs(int group,
                             int startDoc,
                             int maxDocs)
Called by GroupSelector to mark groups to receive documents


nondefaultSort

public final boolean nondefaultSort()
Called by GroupSelector to find out if the ordering is non-default


shouldInclude

public final boolean shouldInclude(int group)
Called by GroupSelector to find out if it should include a given group


nGroups

public final int nGroups()
Get the total number of groups


child

public final int child(int group)
Get the first child of the given group, in properly sorted order


sibling

public final int sibling(int group)
Get the next sibling of the given group, in properly sorted order


parent

public final int parent(int group)
Get the parent of the given group


name

public final String name(int group)
Get the name of a specific group


isSelected

public final boolean isSelected(int group)
Find out whether the given group is selected


nDocHits

public final int nDocHits(int group)
Find out the number of doc hits for the given group


score

public final float score(int group)
Find out the score of the given group


addDoc

public void addDoc(GroupCounts.DocHitMaker docHitMaker)
Add a document hit to the counts


getResult

public ResultFacet getResult()
Retrieve the result facet with its groupings.


sortAndSelect

private void sortAndSelect()
Called during the prep phase for dynamic groups, and in the result building phase for static groups. Sorts the groups based on the facet spec, and performs the final (non-conservative) selection.


buildResultGroup

public ResultGroup buildResultGroup(int parent)

sortGroups

private void sortGroups()
Re-sort the hierarchy according to the facet spec, and store the new child/sibling relationships.


countDescendants

private int countDescendants(int group)
Utility function to count the group and all of its descendants


buildDocHits

private void buildDocHits(int group,
                          ResultGroup resultGroup)
Construct the array of doc hits for the hit group.


sortChildren

private void sortChildren(int parent,
                          int sortKind)

compare

private int compare(int g1,
                    int g2,
                    int sortKind)
Compare two groups for sorting purposes.


compare

private static int compare(int x,
                           int y)
Compare two ints for sorting purposes


compare

private static int compare(float x,
                           float y)
Compare two floats for sorting purposes