Class FacetRequest

  • All Implemented Interfaces:
    Cloneable
    Direct Known Subclasses:
    AssociationFloatSumFacetRequest, AssociationIntSumFacetRequest, CountFacetRequest, ScoreFacetRequest

    public abstract class FacetRequest
    extends Object
    implements Cloneable
    Request to accumulate facet information for a specified facet and possibly also some of its descendants, upto a specified depth.

    The facet request additionally defines what information should be computed within the facet results, if and how should results be ordered, etc.

    An example facet request is to look at all sub-categories of "Author", and return the 10 with the highest counts (sorted by decreasing count).

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

      • FacetRequest

        public FacetRequest​(CategoryPath path,
                            int numResults)
        Initialize the request with a given path, and a requested number of facets results. By default, all returned results would be labeled - to alter this default see setNumLabel(int).

        NOTE: if numResults is given as Integer.MAX_VALUE than all the facet results would be returned, without any limit.

        NOTE: it is assumed that the given CategoryPath is not modified after construction of this object. Otherwise, some things may not function properly, e.g. hashCode().

        Throws:
        IllegalArgumentException - if numResults is ≤ 0
    • Method Detail

      • setNumLabel

        public void setNumLabel​(int numLabel)
      • setDepth

        public void setDepth​(int depth)
      • getCategoryPath

        public final CategoryPath getCategoryPath()
        The root category of this facet request. The categories that are returned as a result of this request will all be descendants of this root.

        NOTE: you should not modify the returned CategoryPath, or otherwise some methonds may not work properly, e.g. hashCode().

      • getDepth

        public final int getDepth()
        How deeply to look under the given category. If the depth is 0, only the category itself is counted. If the depth is 1, its immediate children are also counted, and so on. If the depth is Integer.MAX_VALUE, all the category's descendants are counted.
        TODO (Facet): add AUTO_EXPAND option
      • getNumLabel

        public final int getNumLabel()
        If getNumLabel() If Integer.MAX_VALUE is specified, all results are labled.

        The purpose of this parameter is to avoid having to run the whole faceted search again when the user asks for more values for the facet; The application can ask (getNumResults()) for more values than it needs to show, but keep getNumLabel() only the number it wants to immediately show. The slow-down caused by finding more values is negligible, because the slowest part - finding the categories' paths, is avoided.

        Depending on the LimitsMode, this limit is applied globally or per results node. In the global mode, if this limit is 3, only 3 top results would be labeled. In the per-node mode, if this limit is 3, 3 top children of the target category would be labeled, as well as 3 top children of each of them, and so forth, until the depth defined by getDepth().

        See Also:
        getResultMode()
      • getNumResults

        public final int getNumResults()
        The number of sub-categories to return (at most). If the sub-categories are returned.

        If Integer.MAX_VALUE is specified, all sub-categories are returned.

        Depending on the LimitsMode, this limit is applied globally or per results node. In the global mode, if this limit is 3, only 3 top results would be computed. In the per-node mode, if this limit is 3, 3 top children of the target category would be returned, as well as 3 top children of each of them, and so forth, until the depth defined by getDepth().

        See Also:
        getResultMode()
      • getSortBy

        public final FacetRequest.SortBy getSortBy()
        Specify how should results be sorted.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • createAggregator

        public abstract Aggregator createAggregator​(boolean useComplements,
                                                    FacetArrays arrays,
                                                    org.apache.lucene.index.IndexReader indexReader,
                                                    TaxonomyReader taxonomy)
                                             throws IOException
        Create an aggregator for this facet request. Aggregator action depends on request definition. For a count request, it will usually increment the count for that facet.
        Parameters:
        useComplements - whether the complements optimization is being used for current computation.
        arrays - provider for facet arrays in use for current computation.
        indexReader - index reader in effect.
        taxonomy - reader of taxonomy in effect.
        Throws:
        IOException
      • createCategoryListIterator

        public CategoryListIterator createCategoryListIterator​(org.apache.lucene.index.IndexReader reader,
                                                               TaxonomyReader taxo,
                                                               FacetSearchParams sParams,
                                                               int partition)
                                                        throws IOException
        Create the category list iterator for the specified partition. If a non null cache is provided which contains the required data, use it for the iteration.
        Throws:
        IOException
      • getValueOf

        public abstract double getValueOf​(FacetArrays arrays,
                                          int idx)
        Return the value of a category used for facets computations for this request. For a count request this would be the count for that facet, i.e. an integer number. but for other requests this can be the result of a more complex operation, and the result can be any double precision number. Having this method with a general name value which is double precision allows to have more compact API and code for handling counts and perhaps other requests (such as for associations) very similarly, and by the same code and API, avoiding code duplication.
        Parameters:
        arrays - provider for facet arrays in use for current computation.
        idx - an index into the count arrays now in effect in arrays. E.g., for ordinal number n, with partition, of size partitionSize, now covering n, getValueOf would be invoked with idx being n % partitionSize.
      • supportsComplements

        public boolean supportsComplements()
        Indicates whether this facet request is eligible for applying the complements optimization.
      • requireDocumentScore

        public abstract boolean requireDocumentScore()
        Indicates whether the results of this request depends on each result document's score