Class 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 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​(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
      • 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()
      • 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