org.apache.lucene.facet.search.results
Class MutableFacetResultNode

java.lang.Object
  extended by org.apache.lucene.facet.search.results.MutableFacetResultNode
All Implemented Interfaces:
FacetResultNode

public class MutableFacetResultNode
extends Object
implements FacetResultNode

Mutable implementation for Result of faceted search for a certain taxonomy node.

WARNING: This API is experimental and might change in incompatible ways in the next release.

Constructor Summary
MutableFacetResultNode(FacetResultNode other, boolean takeSubResults)
          Create a mutable facet result node from another result node
MutableFacetResultNode(int ordinal, double value)
          Create a Facet Result Node.
MutableFacetResultNode(int ordinal, double value, double residue, CategoryPath label, List<FacetResultNode> subResults)
          Create a Facet Result Node.
 
Method Summary
 void appendSubResult(FacetResultNode subRes)
          Append a sub result (as last).
 CategoryPath getLabel()
          Category path of the category of this result, or null if not computed, because the application did not request to compute it.
 CategoryPath getLabel(TaxonomyReader taxonomyReader)
          Category path of the category of this result.
 int getNumSubResults()
          Number of sub results
 int getOrdinal()
          Ordinal of the category of this result.
 double getResidue()
          Value of screened out sub results.
 Iterable<? extends FacetResultNode> getSubResults()
          Contained sub results.
 double getValue()
          Value of this result - usually either count or a value derived from some computing on the association of it.
 void increaseResidue(double addedResidue)
          increase the residue for this result.
 void increaseValue(double addedValue)
          increase the value for this result.
 void insertSubResult(FacetResultNode subRes)
          Insert sub result (as first).
 void reset(int ordinal, double value)
          Reset a facet Result Node.
 void setLabel(CategoryPath label)
          Set the label of the category of this result.
 void setResidue(double residue)
          Set the residue.
 void setSubResults(List<FacetResultNode> subResults)
          Set the sub results.
 void setValue(double value)
          Set the value of this result.
static MutableFacetResultNode toImpl(FacetResultNode frn)
          Internal utility: turn a result node into an implementation class with richer API that allows modifying it.
 String toString()
           
 String toString(String prefix)
          String representation of this facet result node.
 void trimSubResults(int size)
          Trim sub results to a given size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MutableFacetResultNode

public MutableFacetResultNode(int ordinal,
                              double value)
Create a Facet Result Node.

Parameters:
ordinal - ordinal in the taxonomy of the category of this result.
value - value this result.

MutableFacetResultNode

public MutableFacetResultNode(int ordinal,
                              double value,
                              double residue,
                              CategoryPath label,
                              List<FacetResultNode> subResults)
Create a Facet Result Node.

Parameters:
ordinal - ordinal in the taxonomy of the category of this result.
value - value of this result.
residue - Value of screened out sub results.
label - label of the category path of this result.
subResults - - sub results, usually descendants, sometimes child results, of this result - depending on the request.

MutableFacetResultNode

public MutableFacetResultNode(FacetResultNode other,
                              boolean takeSubResults)
Create a mutable facet result node from another result node

Parameters:
other - other result node to copy from
takeSubResults - set to true to take also sub results of other node
Method Detail

reset

public void reset(int ordinal,
                  double value)
Reset a facet Result Node.

Used at the population of facet results, not intended for regular use by applications.

Parameters:
ordinal - ordinal in the taxonomy of the category of this result.
value - value of this result.

toString

public String toString()
Overrides:
toString in class Object

toString

public String toString(String prefix)
Description copied from interface: FacetResultNode
String representation of this facet result node. Use with caution: might return a very long string.

Specified by:
toString in interface FacetResultNode
Parameters:
prefix - prefix for each result line

getOrdinal

public final int getOrdinal()
Description copied from interface: FacetResultNode
Ordinal of the category of this result.

Specified by:
getOrdinal in interface FacetResultNode

getLabel

public final CategoryPath getLabel()
Description copied from interface: FacetResultNode
Category path of the category of this result, or null if not computed, because the application did not request to compute it. To force computing the label in case not yet computed use FacetResultNode.getLabel(TaxonomyReader).

Specified by:
getLabel in interface FacetResultNode
See Also:
FacetRequest.getNumLabel(), FacetResultNode.getLabel(TaxonomyReader)

setLabel

public void setLabel(CategoryPath label)
Set the label of the category of this result.

Parameters:
label - the label to set.
See Also:
getLabel()

getValue

public final double getValue()
Description copied from interface: FacetResultNode
Value of this result - usually either count or a value derived from some computing on the association of it.

Specified by:
getValue in interface FacetResultNode

setValue

public void setValue(double value)
Set the value of this result.

Specified by:
setValue in interface FacetResultNode
Parameters:
value - the value to set
See Also:
getValue()

increaseValue

public void increaseValue(double addedValue)
increase the value for this result.

Parameters:
addedValue - the value to add
See Also:
getValue()

getResidue

public final double getResidue()
Description copied from interface: FacetResultNode
Value of screened out sub results.

If only part of valid results are returned, e.g. because top K were requested, provide info on "what else is there under this result node".

Specified by:
getResidue in interface FacetResultNode

setResidue

public void setResidue(double residue)
Set the residue.

Parameters:
residue - the residue to set
See Also:
getResidue()

increaseResidue

public void increaseResidue(double addedResidue)
increase the residue for this result.

Parameters:
addedResidue - the residue to add
See Also:
getResidue()

getSubResults

public final Iterable<? extends FacetResultNode> getSubResults()
Description copied from interface: FacetResultNode
Contained sub results. These are either child facets, if a tree result was requested, or simply descendants, in case tree result was not requested. In the first case, all returned are both descendants of this node in the taxonomy and siblings of each other in the taxonomy. In the latter case they are only guaranteed to be descendants of this node in the taxonomy.

Specified by:
getSubResults in interface FacetResultNode

trimSubResults

public void trimSubResults(int size)
Trim sub results to a given size.

Note: Although the getResidue() is not guaranteed to be accurate, it is worth fixing it, as possible, by taking under account the trimmed sub-nodes.


setSubResults

public void setSubResults(List<FacetResultNode> subResults)
Set the sub results.

Parameters:
subResults - the sub-results to set

appendSubResult

public void appendSubResult(FacetResultNode subRes)
Append a sub result (as last).

Parameters:
subRes - sub-result to be appended

insertSubResult

public void insertSubResult(FacetResultNode subRes)
Insert sub result (as first).

Parameters:
subRes - sub-result to be inserted

getLabel

public final CategoryPath getLabel(TaxonomyReader taxonomyReader)
                            throws IOException
Description copied from interface: FacetResultNode
Category path of the category of this result. If not already computed, will be computed now.

Use with caution: loading a label for results is costly, performance wise. Therefore force labels loading only when really needed.

Specified by:
getLabel in interface FacetResultNode
Parameters:
taxonomyReader - taxonomy reader for forcing (lazy) labeling of this result.
Throws:
IOException - on error
See Also:
FacetRequest.getNumLabel()

getNumSubResults

public final int getNumSubResults()
Description copied from interface: FacetResultNode
Number of sub results

Specified by:
getNumSubResults in interface FacetResultNode

toImpl

public static MutableFacetResultNode toImpl(FacetResultNode frn)
Internal utility: turn a result node into an implementation class with richer API that allows modifying it.

In case that input result node is already of an implementation class only casting is done, but in any case we pay the price of checking "instance of".

Parameters:
frn - facet result node to be turned into an implementation class object


Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.