Class AbstractAggregator

  • All Implemented Interfaces:
    Scorer, FlyweightPrototype<Scorer>
    Direct Known Subclasses:
    LinearAggregator

    public abstract class AbstractAggregator
    extends Object
    implements Scorer
    A Scorer that aggregates a number of underlying delegating scorers, providing equalisation if required.

    An aggregator combines the results of several scorers following some policy (see, e.g., LinearAggregator). In doing so, often the aggregator needs to explore the first scores returned by each scorer, and tune some internal parameters. This procedure, equalisation, is supported by this class: if equalize(int) is provided with a positive number of samples, they will be fetched from the underlying document iterator, scored, and passed to the implementing subclass so that equalisation information can be properly set up.

    Additionally, this class ensures that if several scorers need access to intervals, the document iterator to be scored is decorated with a CachingDocumentIterator, so that several scorer can access intervals.

    Since this class uses the same document iterator for all aggregated scorers, they must be necessarily delegating scorers.

    Implementing subclasses must provide the following methods:

    • setupEqualizationFactors(), which is called in case equalisation is required and must examine actualSamples elements from sampleScore (each element is a tuple of scores, one for each scorer) and use that information to set the equalisation factors (if samples is zero, default values must be applied);
    • score(double[]), which must compute the equalised aggregated score using the given array of scores (each to be thought as a score coming from the respective scorer).

    Additionally, implementing subclasses must remember to call equalize(int) when generating a flyweight copy, so that the state of the aggregator is reproduced correctly.

    • Field Detail

      • documentIterator

        protected DocumentIterator documentIterator
        The current document iterator.
      • n

        protected final int n
        The number of underlying scorers.
      • scorer

        protected final Scorer[] scorer
        The underlying scorers.
      • currScore

        protected final double[] currScore
        The current score.
      • needsCaching

        protected final boolean needsCaching
        Whether we need caching the intervals.
      • sampleDocument

        protected long[] sampleDocument
        Cached sample of document pointers.
      • sampleScore

        protected double[][] sampleScore
        Cached sample of document scores.
      • samples

        protected int samples
        The number of samples for equalisation (0 means no equalisation).
      • currSample

        protected int currSample
        The next sample to be returned, if smaller than actualSamples.
      • actualSamples

        protected int actualSamples
        The actual number of samples obtained (might be less than samples if we exhausted the document iterator).
    • Constructor Detail

      • AbstractAggregator

        public AbstractAggregator​(Scorer[] scorer)
        Creates an aggregator.
        Parameters:
        scorer - the scorers.
    • Method Detail

      • score

        public double score​(Index index)
        Description copied from interface: Scorer
        Returns a score for the current document of the last document iterator given to Scorer.wrap(DocumentIterator), but considering only a given index (optional operation).
        Specified by:
        score in interface Scorer
        Parameters:
        index - the only index to be considered.
        Returns:
        the score.
      • equalize

        public void equalize​(int samples)
        Set the number of samples for equalisation.
        Parameters:
        samples - the number of samples to be used to equalise scores; a value of zero disables equalisation.
        See Also:
        AbstractAggregator
      • setWeights

        public boolean setWeights​(Reference2DoubleMap<Index> index2weight)
        Delegates to the underlying scorers.
        Specified by:
        setWeights in interface Scorer
        Parameters:
        index2weight - a map from indices to weights.
        Returns:
        true if at least one underlying scorer supports weights.
      • getWeights

        public Reference2DoubleMap<Index> getWeights()
        Delegates to the underlying scorers.
        Specified by:
        getWeights in interface Scorer
        Returns:
        true if at least one underlying scorer supports weights.
      • usesIntervals

        public boolean usesIntervals()
        Delegates to the underlying scorers.
        Specified by:
        usesIntervals in interface Scorer
        Returns:
        true if at least one underlying scorer uses intervals.
      • score

        protected abstract double score​(double[] score)
        Computes an aggregated score using the given array of basic scores. The array is parallel to scorer.
        Parameters:
        score - an array of scores.
        Returns:
        the aggregated scorer.
      • setupEqualizationFactors

        protected abstract void setupEqualizationFactors()
        Sets up the equalisation factors.

        Implementations should look into sampleScore and set up the equalisation logic. Note that this method is responsible for setting up appropriate equalisation factors even if no equalisation is required (e.g., setting all factors to 1 ).

      • nextDocument

        public long nextDocument()
                          throws IOException
        Description copied from interface: Scorer
        Returns the next document provided by this scorer, or -1 if no more documents are available.
        Specified by:
        nextDocument in interface Scorer
        Returns:
        the next document, or -1 if no more documents are available.
        Throws:
        IOException