Skip to content

Commit 1f55bf1

Browse files
committed
HSEARCH-5133 Push type-sel into each Lucene*Aggregation
1 parent 3830727 commit 1f55bf1

File tree

3 files changed

+41
-19
lines changed

3 files changed

+41
-19
lines changed

backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/aggregation/impl/AbstractLuceneMetricCompensatedSumAggregation.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,16 @@ public K extract(AggregationExtractContext context) {
7676

7777
abstract E extractEncoded(AggregationExtractContext context, LuceneNumericDomain<E> numericDomain);
7878

79-
protected static class TypeSelector<F> implements FieldMetricAggregationBuilder.TypeSelector {
80-
private final AbstractLuceneNumericFieldCodec<F, ?> codec;
81-
private final LuceneSearchIndexScope<?> scope;
82-
private final LuceneSearchIndexValueFieldContext<F> field;
83-
private final String operation;
79+
protected abstract static class TypeSelector<F> implements FieldMetricAggregationBuilder.TypeSelector {
80+
protected final AbstractLuceneNumericFieldCodec<F, ?> codec;
81+
protected final LuceneSearchIndexScope<?> scope;
82+
protected final LuceneSearchIndexValueFieldContext<F> field;
8483

8584
protected TypeSelector(AbstractLuceneNumericFieldCodec<F, ?> codec,
86-
LuceneSearchIndexScope<?> scope, LuceneSearchIndexValueFieldContext<F> field,
87-
String operation) {
85+
LuceneSearchIndexScope<?> scope, LuceneSearchIndexValueFieldContext<F> field) {
8886
this.codec = codec;
8987
this.scope = scope;
9088
this.field = field;
91-
this.operation = operation;
9289
}
9390

9491
@Override
@@ -101,16 +98,11 @@ protected TypeSelector(AbstractLuceneNumericFieldCodec<F, ?> codec,
10198
.withConvertedType( expectedType, field );
10299
}
103100

104-
if ( "sum".equals( operation ) ) {
105-
return new LuceneSumCompensatedSumAggregation.Builder<>( codec, scope, field, projectionConverter );
106-
}
107-
else if ( "avg".equals( operation ) ) {
108-
return new LuceneAvgCompensatedSumAggregation.Builder<>( codec, scope, field, projectionConverter );
109-
}
110-
else {
111-
throw new AssertionFailure( "Aggregation operation not supported: " + operation );
112-
}
101+
return getFtBuilder( projectionConverter );
113102
}
103+
104+
protected abstract <T> Builder<F, ? extends Number, T> getFtBuilder(
105+
ProjectionConverter<F, ? extends T> projectionConverter);
114106
}
115107

116108
protected abstract static class Builder<F, E extends Number, K> extends AbstractBuilder<K>

backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/aggregation/impl/LuceneAvgCompensatedSumAggregation.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,22 @@ protected Factory(AbstractLuceneNumericFieldCodec<F, ?> codec) {
6161
@Override
6262
public FieldMetricAggregationBuilder.TypeSelector create(LuceneSearchIndexScope<?> scope,
6363
LuceneSearchIndexValueFieldContext<F> field) {
64-
return new TypeSelector<>( codec, scope, field, "avg" );
64+
return new FunctionTypeSelector<>( codec, scope, field );
65+
}
66+
}
67+
68+
protected static class FunctionTypeSelector<F> extends TypeSelector<F>
69+
implements FieldMetricAggregationBuilder.TypeSelector {
70+
71+
protected FunctionTypeSelector(AbstractLuceneNumericFieldCodec<F, ?> codec, LuceneSearchIndexScope<?> scope,
72+
LuceneSearchIndexValueFieldContext<F> field) {
73+
super( codec, scope, field );
74+
}
75+
76+
@Override
77+
protected <T> Builder<F, ? extends Number, T> getFtBuilder(
78+
ProjectionConverter<F, ? extends T> projectionConverter) {
79+
return new Builder<>( codec, scope, field, projectionConverter );
6580
}
6681
}
6782

backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/aggregation/impl/LuceneSumCompensatedSumAggregation.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,22 @@ protected Factory(AbstractLuceneNumericFieldCodec<F, ?> codec) {
5454
@Override
5555
public FieldMetricAggregationBuilder.TypeSelector create(LuceneSearchIndexScope<?> scope,
5656
LuceneSearchIndexValueFieldContext<F> field) {
57-
return new TypeSelector<>( codec, scope, field, "sum" );
57+
return new FunctionTypeSelector<>( codec, scope, field );
58+
}
59+
}
60+
61+
protected static class FunctionTypeSelector<F> extends TypeSelector<F>
62+
implements FieldMetricAggregationBuilder.TypeSelector {
63+
64+
protected FunctionTypeSelector(AbstractLuceneNumericFieldCodec<F, ?> codec, LuceneSearchIndexScope<?> scope,
65+
LuceneSearchIndexValueFieldContext<F> field) {
66+
super( codec, scope, field );
67+
}
68+
69+
@Override
70+
protected <T> Builder<F, ? extends Number, T> getFtBuilder(
71+
ProjectionConverter<F, ? extends T> projectionConverter) {
72+
return new Builder<>( codec, scope, field, projectionConverter );
5873
}
5974
}
6075

0 commit comments

Comments
 (0)