forked from hibernate/hibernate-search
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-5133 Refactor LuceneMetric*Aggregation classes
Extracting one subclass for each operation name
- Loading branch information
Showing
15 changed files
with
309 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...nate/search/backend/lucene/types/aggregation/impl/LuceneAvgCompensatedSumAggregation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.search.backend.lucene.types.aggregation.impl; | ||
|
||
import org.hibernate.search.backend.lucene.lowlevel.aggregation.collector.impl.CompensatedSumCollectorFactory; | ||
import org.hibernate.search.backend.lucene.lowlevel.aggregation.collector.impl.CountCollectorFactory; | ||
import org.hibernate.search.backend.lucene.lowlevel.docvalues.impl.JoiningLongMultiValuesSource; | ||
import org.hibernate.search.backend.lucene.search.aggregation.impl.AggregationExtractContext; | ||
import org.hibernate.search.backend.lucene.search.aggregation.impl.AggregationRequestContext; | ||
import org.hibernate.search.backend.lucene.types.lowlevel.impl.LuceneNumericDomain; | ||
|
||
public class LuceneAvgCompensatedSumAggregation<F, E extends Number, K> | ||
extends AbstractLuceneMetricCompensatedSumAggregation<F, E, K> { | ||
|
||
LuceneAvgCompensatedSumAggregation(Builder<F, E, K> builder) { | ||
super( builder ); | ||
} | ||
|
||
@Override | ||
void fillCollectors(JoiningLongMultiValuesSource source, AggregationRequestContext context, | ||
LuceneNumericDomain<E> numericDomain) { | ||
CompensatedSumCollectorFactory sumCollectorFactory = new CompensatedSumCollectorFactory( source, | ||
numericDomain::sortedDocValueToDouble ); | ||
compensatedSumCollectorKey = sumCollectorFactory.getCollectorKey(); | ||
context.requireCollector( sumCollectorFactory ); | ||
|
||
CountCollectorFactory countCollectorFactory = new CountCollectorFactory( source ); | ||
collectorKey = countCollectorFactory.getCollectorKey(); | ||
context.requireCollector( countCollectorFactory ); | ||
} | ||
|
||
@Override | ||
E extractEncoded(AggregationExtractContext context, LuceneNumericDomain<E> numericDomain) { | ||
Double sum = context.getFacets( compensatedSumCollectorKey ); | ||
Long counts = context.getFacets( collectorKey ); | ||
double avg = ( sum / counts ); | ||
return numericDomain.doubleToTerm( avg ); | ||
} | ||
} |
Oops, something went wrong.