Skip to content

Commit

Permalink
HSEARCH-5133 Push factories into each Lucene*Aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
fax4ever committed Aug 28, 2024
1 parent 9ce2607 commit e083fbe
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
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.search.common.impl.AbstractLuceneCodecAwareSearchQueryElementFactory;
import org.hibernate.search.backend.lucene.search.common.impl.LuceneSearchIndexScope;
import org.hibernate.search.backend.lucene.search.common.impl.LuceneSearchIndexValueFieldContext;
import org.hibernate.search.backend.lucene.types.codec.impl.AbstractLuceneNumericFieldCodec;
Expand Down Expand Up @@ -82,32 +81,13 @@ public K extract(AggregationExtractContext context) {

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

public static class Factory<F>
extends AbstractLuceneCodecAwareSearchQueryElementFactory<FieldMetricAggregationBuilder.TypeSelector,
F,
AbstractLuceneNumericFieldCodec<F, ?>> {

private final String operation;

protected Factory(AbstractLuceneNumericFieldCodec<F, ?> codec, String operation) {
super( codec );
this.operation = operation;
}

@Override
public FieldMetricAggregationBuilder.TypeSelector create(LuceneSearchIndexScope<?> scope,
LuceneSearchIndexValueFieldContext<F> field) {
return new TypeSelector<>( codec, scope, field, operation );
}
}

private static class TypeSelector<F> implements FieldMetricAggregationBuilder.TypeSelector {
protected static class TypeSelector<F> implements FieldMetricAggregationBuilder.TypeSelector {
private final AbstractLuceneNumericFieldCodec<F, ?> codec;
private final LuceneSearchIndexScope<?> scope;
private final LuceneSearchIndexValueFieldContext<F> field;
private final String operation;

private TypeSelector(AbstractLuceneNumericFieldCodec<F, ?> codec,
protected TypeSelector(AbstractLuceneNumericFieldCodec<F, ?> codec,
LuceneSearchIndexScope<?> scope, LuceneSearchIndexValueFieldContext<F> field,
String operation) {
this.codec = codec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
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.search.common.impl.AbstractLuceneCodecAwareSearchQueryElementFactory;
import org.hibernate.search.backend.lucene.search.common.impl.LuceneSearchIndexScope;
import org.hibernate.search.backend.lucene.search.common.impl.LuceneSearchIndexValueFieldContext;
import org.hibernate.search.backend.lucene.types.codec.impl.AbstractLuceneNumericFieldCodec;
Expand Down Expand Up @@ -94,32 +93,13 @@ public K extract(AggregationExtractContext context) {
}
}

public static class Factory<F>
extends AbstractLuceneCodecAwareSearchQueryElementFactory<FieldMetricAggregationBuilder.TypeSelector,
F,
AbstractLuceneNumericFieldCodec<F, ?>> {

private final String operation;

protected Factory(AbstractLuceneNumericFieldCodec<F, ?> codec, String operation) {
super( codec );
this.operation = operation;
}

@Override
public FieldMetricAggregationBuilder.TypeSelector create(LuceneSearchIndexScope<?> scope,
LuceneSearchIndexValueFieldContext<F> field) {
return new TypeSelector<>( codec, scope, field, operation );
}
}

private static class TypeSelector<F> implements FieldMetricAggregationBuilder.TypeSelector {
protected static class TypeSelector<F> implements FieldMetricAggregationBuilder.TypeSelector {
private final AbstractLuceneNumericFieldCodec<F, ?> codec;
private final LuceneSearchIndexScope<?> scope;
private final LuceneSearchIndexValueFieldContext<F> field;
private final String operation;

private TypeSelector(AbstractLuceneNumericFieldCodec<F, ?> codec,
protected TypeSelector(AbstractLuceneNumericFieldCodec<F, ?> codec,
LuceneSearchIndexScope<?> scope, LuceneSearchIndexValueFieldContext<F> field,
String operation) {
this.codec = codec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
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.search.common.impl.AbstractLuceneCodecAwareSearchQueryElementFactory;
import org.hibernate.search.backend.lucene.search.common.impl.LuceneSearchIndexScope;
import org.hibernate.search.backend.lucene.search.common.impl.LuceneSearchIndexValueFieldContext;
import org.hibernate.search.backend.lucene.types.codec.impl.AbstractLuceneNumericFieldCodec;
import org.hibernate.search.engine.search.aggregation.spi.FieldMetricAggregationBuilder;
import org.hibernate.search.util.common.AssertionFailure;

public abstract class AbstractLuceneMetricNumericLongAggregation extends AbstractLuceneNestableAggregation<Long> {

Expand Down Expand Up @@ -53,31 +47,4 @@ public Long extract(AggregationExtractContext context) {
return context.getFacets( collectorKey );
}
}

public static class Factory<F>
extends AbstractLuceneCodecAwareSearchQueryElementFactory<FieldMetricAggregationBuilder<Long>,
F,
AbstractLuceneNumericFieldCodec<F, ?>> {

private final String operation;

protected Factory(AbstractLuceneNumericFieldCodec<F, ?> codec, String operation) {
super( codec );
this.operation = operation;
}

@Override
public FieldMetricAggregationBuilder<Long> create(LuceneSearchIndexScope<?> scope,
LuceneSearchIndexValueFieldContext<F> field) {
if ( "value_count".equals( operation ) ) {
return new LuceneCountNumericLongAggregation.Builder( scope, field );
}
else if ( "cardinality".equals( operation ) ) {
return new LuceneCountDistinctNumericLongAggregation.Builder( scope, field );
}
else {
throw new AssertionFailure( "Aggregation operation not supported: " + operation );
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
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.search.common.impl.AbstractLuceneCodecAwareSearchQueryElementFactory;
import org.hibernate.search.backend.lucene.search.common.impl.LuceneSearchIndexScope;
import org.hibernate.search.backend.lucene.search.common.impl.LuceneSearchIndexValueFieldContext;
import org.hibernate.search.backend.lucene.types.codec.impl.AbstractLuceneNumericFieldCodec;
import org.hibernate.search.backend.lucene.types.lowlevel.impl.LuceneNumericDomain;
import org.hibernate.search.engine.backend.types.converter.spi.ProjectionConverter;
import org.hibernate.search.engine.search.aggregation.spi.FieldMetricAggregationBuilder;

public class LuceneAvgCompensatedSumAggregation<F, E extends Number, K>
extends AbstractLuceneMetricCompensatedSumAggregation<F, E, K> {

public static <F> Factory<F> factory(AbstractLuceneNumericFieldCodec<F, ?> codec) {
return new Factory<>( codec, "avg" );
return new Factory<>( codec );
}

LuceneAvgCompensatedSumAggregation(Builder<F, E, K> builder) {
Expand Down Expand Up @@ -47,6 +49,22 @@ E extractEncoded(AggregationExtractContext context, LuceneNumericDomain<E> numer
return numericDomain.doubleToTerm( avg );
}

public static class Factory<F>
extends AbstractLuceneCodecAwareSearchQueryElementFactory<FieldMetricAggregationBuilder.TypeSelector,
F,
AbstractLuceneNumericFieldCodec<F, ?>> {

protected Factory(AbstractLuceneNumericFieldCodec<F, ?> codec) {
super( codec );
}

@Override
public FieldMetricAggregationBuilder.TypeSelector create(LuceneSearchIndexScope<?> scope,
LuceneSearchIndexValueFieldContext<F> field) {
return new TypeSelector<>( codec, scope, field, "avg" );
}
}

protected static class Builder<F, E extends Number, K>
extends AbstractLuceneMetricCompensatedSumAggregation.Builder<F, E, K> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
import org.hibernate.search.backend.lucene.lowlevel.aggregation.collector.impl.SumCollectorFactory;
import org.hibernate.search.backend.lucene.lowlevel.docvalues.impl.JoiningLongMultiValuesSource;
import org.hibernate.search.backend.lucene.search.aggregation.impl.AggregationRequestContext;
import org.hibernate.search.backend.lucene.search.common.impl.AbstractLuceneCodecAwareSearchQueryElementFactory;
import org.hibernate.search.backend.lucene.search.common.impl.LuceneSearchIndexScope;
import org.hibernate.search.backend.lucene.search.common.impl.LuceneSearchIndexValueFieldContext;
import org.hibernate.search.backend.lucene.types.codec.impl.AbstractLuceneNumericFieldCodec;
import org.hibernate.search.engine.backend.types.converter.spi.ProjectionConverter;
import org.hibernate.search.engine.search.aggregation.spi.FieldMetricAggregationBuilder;

public class LuceneAvgNumericFieldAggregation<F, E extends Number, K>
extends AbstractLuceneMetricNumericFieldAggregation<F, E, K> {

public static <F> Factory<F> factory(AbstractLuceneNumericFieldCodec<F, ?> codec) {
return new Factory<>( codec, "avg" );
return new Factory<>( codec );
}

LuceneAvgNumericFieldAggregation(Builder<F, E, K> builder) {
Expand All @@ -34,6 +36,22 @@ void fillCollectors(JoiningLongMultiValuesSource source, AggregationRequestConte
context.requireCollector( countCollectorFactory );
}

public static class Factory<F>
extends AbstractLuceneCodecAwareSearchQueryElementFactory<FieldMetricAggregationBuilder.TypeSelector,
F,
AbstractLuceneNumericFieldCodec<F, ?>> {

protected Factory(AbstractLuceneNumericFieldCodec<F, ?> codec) {
super( codec );
}

@Override
public FieldMetricAggregationBuilder.TypeSelector create(LuceneSearchIndexScope<?> scope,
LuceneSearchIndexValueFieldContext<F> field) {
return new TypeSelector<>( codec, scope, field, "avg" );
}
}

protected static class Builder<F, E extends Number, K>
extends AbstractLuceneMetricNumericFieldAggregation.Builder<F, E, K> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.hibernate.search.backend.lucene.lowlevel.aggregation.collector.impl.CountDistinctCollectorFactory;
import org.hibernate.search.backend.lucene.lowlevel.docvalues.impl.JoiningLongMultiValuesSource;
import org.hibernate.search.backend.lucene.search.aggregation.impl.AggregationRequestContext;
import org.hibernate.search.backend.lucene.search.common.impl.AbstractLuceneCodecAwareSearchQueryElementFactory;
import org.hibernate.search.backend.lucene.search.common.impl.LuceneSearchIndexScope;
import org.hibernate.search.backend.lucene.search.common.impl.LuceneSearchIndexValueFieldContext;
import org.hibernate.search.backend.lucene.types.codec.impl.AbstractLuceneNumericFieldCodec;
Expand All @@ -15,7 +16,7 @@
public class LuceneCountDistinctNumericLongAggregation extends AbstractLuceneMetricNumericLongAggregation {

public static <F> Factory<F> factory(AbstractLuceneNumericFieldCodec<F, ?> codec) {
return new Factory<>( codec, "cardinality" );
return new Factory<>( codec );
}

LuceneCountDistinctNumericLongAggregation(Builder builder) {
Expand All @@ -29,6 +30,22 @@ void fillCollectors(JoiningLongMultiValuesSource source, AggregationRequestConte
context.requireCollector( collectorFactory );
}

protected static class Factory<F>
extends AbstractLuceneCodecAwareSearchQueryElementFactory<FieldMetricAggregationBuilder<Long>,
F,
AbstractLuceneNumericFieldCodec<F, ?>> {

protected Factory(AbstractLuceneNumericFieldCodec<F, ?> codec) {
super( codec );
}

@Override
public FieldMetricAggregationBuilder<Long> create(LuceneSearchIndexScope<?> scope,
LuceneSearchIndexValueFieldContext<F> field) {
return new Builder( scope, field );
}
}

protected static class Builder extends AbstractBuilder<Long> implements FieldMetricAggregationBuilder<Long> {
public Builder(LuceneSearchIndexScope<?> scope, LuceneSearchIndexValueFieldContext<?> field) {
super( scope, field );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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.AggregationRequestContext;
import org.hibernate.search.backend.lucene.search.common.impl.AbstractLuceneCodecAwareSearchQueryElementFactory;
import org.hibernate.search.backend.lucene.search.common.impl.LuceneSearchIndexScope;
import org.hibernate.search.backend.lucene.search.common.impl.LuceneSearchIndexValueFieldContext;
import org.hibernate.search.backend.lucene.types.codec.impl.AbstractLuceneNumericFieldCodec;
Expand All @@ -15,7 +16,7 @@
public class LuceneCountNumericLongAggregation extends AbstractLuceneMetricNumericLongAggregation {

public static <F> Factory<F> factory(AbstractLuceneNumericFieldCodec<F, ?> codec) {
return new Factory<>( codec, "value_count" );
return new Factory<>( codec );
}

LuceneCountNumericLongAggregation(Builder builder) {
Expand All @@ -29,6 +30,22 @@ void fillCollectors(JoiningLongMultiValuesSource source, AggregationRequestConte
context.requireCollector( collectorFactory );
}

protected static class Factory<F>
extends AbstractLuceneCodecAwareSearchQueryElementFactory<FieldMetricAggregationBuilder<Long>,
F,
AbstractLuceneNumericFieldCodec<F, ?>> {

protected Factory(AbstractLuceneNumericFieldCodec<F, ?> codec) {
super( codec );
}

@Override
public FieldMetricAggregationBuilder<Long> create(LuceneSearchIndexScope<?> scope,
LuceneSearchIndexValueFieldContext<F> field) {
return new Builder( scope, field );
}
}

protected static class Builder extends AbstractBuilder<Long> implements FieldMetricAggregationBuilder<Long> {
public Builder(LuceneSearchIndexScope<?> scope, LuceneSearchIndexValueFieldContext<?> field) {
super( scope, field );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
import org.hibernate.search.backend.lucene.lowlevel.aggregation.collector.impl.MaxCollectorFactory;
import org.hibernate.search.backend.lucene.lowlevel.docvalues.impl.JoiningLongMultiValuesSource;
import org.hibernate.search.backend.lucene.search.aggregation.impl.AggregationRequestContext;
import org.hibernate.search.backend.lucene.search.common.impl.AbstractLuceneCodecAwareSearchQueryElementFactory;
import org.hibernate.search.backend.lucene.search.common.impl.LuceneSearchIndexScope;
import org.hibernate.search.backend.lucene.search.common.impl.LuceneSearchIndexValueFieldContext;
import org.hibernate.search.backend.lucene.types.codec.impl.AbstractLuceneNumericFieldCodec;
import org.hibernate.search.engine.backend.types.converter.spi.ProjectionConverter;
import org.hibernate.search.engine.search.aggregation.spi.FieldMetricAggregationBuilder;

public class LuceneMaxNumericFieldAggregation<F, E extends Number, K>
extends AbstractLuceneMetricNumericFieldAggregation<F, E, K> {

public static <F> Factory<F> factory(AbstractLuceneNumericFieldCodec<F, ?> codec) {
return new Factory<>( codec, "max" );
return new Factory<>( codec );
}

LuceneMaxNumericFieldAggregation(Builder<F, E, K> builder) {
Expand All @@ -30,6 +32,22 @@ void fillCollectors(JoiningLongMultiValuesSource source, AggregationRequestConte
context.requireCollector( collectorFactory );
}

public static class Factory<F>
extends AbstractLuceneCodecAwareSearchQueryElementFactory<FieldMetricAggregationBuilder.TypeSelector,
F,
AbstractLuceneNumericFieldCodec<F, ?>> {

protected Factory(AbstractLuceneNumericFieldCodec<F, ?> codec) {
super( codec );
}

@Override
public FieldMetricAggregationBuilder.TypeSelector create(LuceneSearchIndexScope<?> scope,
LuceneSearchIndexValueFieldContext<F> field) {
return new TypeSelector<>( codec, scope, field, "max" );
}
}

protected static class Builder<F, E extends Number, K>
extends AbstractLuceneMetricNumericFieldAggregation.Builder<F, E, K> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
import org.hibernate.search.backend.lucene.lowlevel.aggregation.collector.impl.MinCollectorFactory;
import org.hibernate.search.backend.lucene.lowlevel.docvalues.impl.JoiningLongMultiValuesSource;
import org.hibernate.search.backend.lucene.search.aggregation.impl.AggregationRequestContext;
import org.hibernate.search.backend.lucene.search.common.impl.AbstractLuceneCodecAwareSearchQueryElementFactory;
import org.hibernate.search.backend.lucene.search.common.impl.LuceneSearchIndexScope;
import org.hibernate.search.backend.lucene.search.common.impl.LuceneSearchIndexValueFieldContext;
import org.hibernate.search.backend.lucene.types.codec.impl.AbstractLuceneNumericFieldCodec;
import org.hibernate.search.engine.backend.types.converter.spi.ProjectionConverter;
import org.hibernate.search.engine.search.aggregation.spi.FieldMetricAggregationBuilder;

public class LuceneMinNumericFieldAggregation<F, E extends Number, K>
extends AbstractLuceneMetricNumericFieldAggregation<F, E, K> {

public static <F> Factory<F> factory(AbstractLuceneNumericFieldCodec<F, ?> codec) {
return new Factory<>( codec, "min" );
return new Factory<>( codec );
}

LuceneMinNumericFieldAggregation(Builder<F, E, K> builder) {
Expand All @@ -30,6 +32,22 @@ void fillCollectors(JoiningLongMultiValuesSource source, AggregationRequestConte
context.requireCollector( collectorFactory );
}

public static class Factory<F>
extends AbstractLuceneCodecAwareSearchQueryElementFactory<FieldMetricAggregationBuilder.TypeSelector,
F,
AbstractLuceneNumericFieldCodec<F, ?>> {

protected Factory(AbstractLuceneNumericFieldCodec<F, ?> codec) {
super( codec );
}

@Override
public FieldMetricAggregationBuilder.TypeSelector create(LuceneSearchIndexScope<?> scope,
LuceneSearchIndexValueFieldContext<F> field) {
return new TypeSelector<>( codec, scope, field, "min" );
}
}

protected static class Builder<F, E extends Number, K>
extends AbstractLuceneMetricNumericFieldAggregation.Builder<F, E, K> {

Expand Down
Loading

0 comments on commit e083fbe

Please sign in to comment.