Skip to content

Commit 2a56f99

Browse files
committed
HSEARCH-4577 Rename to ProjectionCollector
1 parent 116750c commit 2a56f99

File tree

102 files changed

+769
-738
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+769
-738
lines changed

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/logging/impl/Log.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ SearchException invalidFieldValueType(@FormatWith(ClassFormatter.class) Class<?>
602602
@Message(id = ID_OFFSET + 113,
603603
value = "Invalid cardinality for projection on field '%1$s': the projection is single-valued,"
604604
+ " but this field is multi-valued."
605-
+ " Make sure to call '.accumulator(...)' when you create the projection.")
605+
+ " Make sure to call '.collector(...)' when you create the projection.")
606606
SearchException invalidSingleValuedProjectionOnMultiValuedField(String absolutePath, @Param EventContext context);
607607

608608
@Message(id = ID_OFFSET + 117,
@@ -732,9 +732,9 @@ SearchException invalidContextForProjectionOnField(String absolutePath,
732732
value = "Invalid cardinality for projection on field '%1$s': the projection is single-valued,"
733733
+ " but this field is effectively multi-valued in this context,"
734734
+ " because parent object field '%2$s' is multi-valued."
735-
+ " Either call '.accumulator(...)' when you create the projection on field '%1$s',"
735+
+ " Either call '.collector(...)' when you create the projection on field '%1$s',"
736736
+ " or wrap that projection in an object projection like this:"
737-
+ " 'f.object(\"%2$s\").from(<the projection on field %1$s>).as(...).accumulator(...)'.")
737+
+ " 'f.object(\"%2$s\").from(<the projection on field %1$s>).as(...).collector(...)'.")
738738
SearchException invalidSingleValuedProjectionOnValueFieldInMultiValuedObjectField(String absolutePath,
739739
String objectFieldAbsolutePath);
740740

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/search/highlighter/impl/ElasticsearchSearchHighlighter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.hibernate.search.backend.elasticsearch.search.common.impl.ElasticsearchSearchIndexScope;
1515
import org.hibernate.search.engine.search.highlighter.SearchHighlighter;
1616
import org.hibernate.search.engine.search.highlighter.spi.SearchHighlighterType;
17-
import org.hibernate.search.engine.search.projection.ProjectionAccumulator;
17+
import org.hibernate.search.engine.search.projection.ProjectionCollector;
1818
import org.hibernate.search.util.common.logging.impl.LoggerFactory;
1919

2020
import com.google.gson.JsonObject;
@@ -31,7 +31,7 @@ public interface ElasticsearchSearchHighlighter extends SearchHighlighter {
3131

3232
SearchHighlighterType type();
3333

34-
boolean isCompatible(ProjectionAccumulator.Provider<?, ?> accumulatorProvider);
34+
boolean isCompatible(ProjectionCollector.Provider<?, ?> collectorProvider);
3535

3636
static ElasticsearchSearchHighlighter from(ElasticsearchSearchIndexScope<?> scope, SearchHighlighter highlighter) {
3737
if ( !( highlighter instanceof ElasticsearchSearchHighlighter ) ) {

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/search/highlighter/impl/ElasticsearchSearchHighlighterImpl.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.hibernate.search.engine.search.highlighter.spi.BoundaryScannerType;
2222
import org.hibernate.search.engine.search.highlighter.spi.SearchHighlighterBuilder;
2323
import org.hibernate.search.engine.search.highlighter.spi.SearchHighlighterType;
24-
import org.hibernate.search.engine.search.projection.ProjectionAccumulator;
24+
import org.hibernate.search.engine.search.projection.ProjectionCollector;
2525

2626
import com.google.gson.JsonArray;
2727
import com.google.gson.JsonObject;
@@ -143,9 +143,9 @@ public SearchHighlighterType type() {
143143
}
144144

145145
@Override
146-
public boolean isCompatible(ProjectionAccumulator.Provider<?, ?> provider) {
147-
return !provider.isSingleValued()
148-
|| ( provider.isSingleValued() && ( numberOfFragments != null && numberOfFragments.equals( 1 ) ) );
146+
public boolean isCompatible(ProjectionCollector.Provider<?, ?> collectorProvider) {
147+
return !collectorProvider.isSingleValued()
148+
|| ( collectorProvider.isSingleValued() && ( numberOfFragments != null && numberOfFragments.equals( 1 ) ) );
149149
}
150150

151151
private JsonObject toJson(JsonObject result) {

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/search/projection/impl/AccumulatingSourceExtractor.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import org.hibernate.search.backend.elasticsearch.gson.impl.JsonElementTypes;
1313
import org.hibernate.search.backend.elasticsearch.gson.impl.UnexpectedJsonElementTypeException;
1414
import org.hibernate.search.engine.search.loading.spi.ProjectionHitMapper;
15-
import org.hibernate.search.engine.search.projection.ProjectionAccumulator;
15+
import org.hibernate.search.engine.search.projection.ProjectionCollector;
1616

1717
import com.google.gson.JsonElement;
1818
import com.google.gson.JsonObject;
@@ -24,18 +24,18 @@ abstract class AccumulatingSourceExtractor<E, V, A, P>
2424
JsonAccessor.root().property( "_source" ).asArray();
2525

2626
private final String[] fieldPathComponents;
27-
final ProjectionAccumulator<E, V, A, P> accumulator;
27+
final ProjectionCollector<E, V, A, P> collector;
2828

2929
public AccumulatingSourceExtractor(String[] fieldPathComponents,
30-
ProjectionAccumulator<E, V, A, P> accumulator) {
30+
ProjectionCollector<E, V, A, P> collector) {
3131
this.fieldPathComponents = fieldPathComponents;
32-
this.accumulator = accumulator;
32+
this.collector = collector;
3333
}
3434

3535
@Override
3636
public final A extract(ProjectionHitMapper<?> projectionHitMapper, JsonObject hit,
3737
JsonObject source, ProjectionExtractContext context) {
38-
A accumulated = accumulator.createInitial();
38+
A accumulated = collector.createInitial();
3939
accumulated = collect( projectionHitMapper, hit, source, context, accumulated, 0 );
4040
return accumulated;
4141
}
@@ -83,17 +83,17 @@ private A collectTargetField(ProjectionHitMapper<?> projectionHitMapper, JsonObj
8383
}
8484
else if ( fieldValue.isJsonNull() ) {
8585
// Present, but null
86-
return accumulator.accumulate( accumulated, extract( projectionHitMapper, hit, fieldValue, context ) );
86+
return collector.accumulate( accumulated, extract( projectionHitMapper, hit, fieldValue, context ) );
8787
}
8888
else if ( !canDecodeArrays() && fieldValue.isJsonArray() ) {
8989
for ( JsonElement childElement : fieldValue.getAsJsonArray() ) {
90-
accumulated = accumulator.accumulate( accumulated,
90+
accumulated = collector.accumulate( accumulated,
9191
extract( projectionHitMapper, hit, childElement, context ) );
9292
}
9393
return accumulated;
9494
}
9595
else {
96-
return accumulator.accumulate( accumulated, extract( projectionHitMapper, hit, fieldValue, context ) );
96+
return collector.accumulate( accumulated, extract( projectionHitMapper, hit, fieldValue, context ) );
9797
}
9898
}
9999

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/search/projection/impl/ElasticsearchCompositeProjection.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import org.hibernate.search.backend.elasticsearch.search.common.impl.ElasticsearchSearchIndexScope;
1010
import org.hibernate.search.engine.search.loading.spi.LoadingResult;
1111
import org.hibernate.search.engine.search.loading.spi.ProjectionHitMapper;
12-
import org.hibernate.search.engine.search.projection.ProjectionAccumulator;
12+
import org.hibernate.search.engine.search.projection.ProjectionCollector;
1313
import org.hibernate.search.engine.search.projection.SearchProjection;
1414
import org.hibernate.search.engine.search.projection.spi.CompositeProjectionBuilder;
1515
import org.hibernate.search.engine.search.projection.spi.ProjectionCompositor;
@@ -31,22 +31,22 @@ class ElasticsearchCompositeProjection<E, V, A, P>
3131

3232
private final ElasticsearchSearchProjection<?>[] inners;
3333
private final ProjectionCompositor<E, V> compositor;
34-
private final ProjectionAccumulator<E, V, A, P> accumulator;
34+
private final ProjectionCollector<E, V, A, P> collector;
3535

3636
public ElasticsearchCompositeProjection(Builder builder, ElasticsearchSearchProjection<?>[] inners,
37-
ProjectionCompositor<E, V> compositor, ProjectionAccumulator<E, V, A, P> accumulator) {
37+
ProjectionCompositor<E, V> compositor, ProjectionCollector<E, V, A, P> collector) {
3838
super( builder.scope );
3939
this.inners = inners;
4040
this.compositor = compositor;
41-
this.accumulator = accumulator;
41+
this.collector = collector;
4242
}
4343

4444
@Override
4545
public String toString() {
4646
return getClass().getSimpleName() + "["
4747
+ "inners=" + Arrays.toString( inners )
4848
+ ", compositor=" + compositor
49-
+ ", accumulator=" + accumulator
49+
+ ", collector=" + collector
5050
+ "]";
5151
}
5252

@@ -71,30 +71,30 @@ public String toString() {
7171
return getClass().getSimpleName() + "["
7272
+ "inners=" + Arrays.toString( inners )
7373
+ ", compositor=" + compositor
74-
+ ", accumulator=" + accumulator
74+
+ ", collector=" + collector
7575
+ "]";
7676
}
7777

7878
@Override
7979
public A extract(ProjectionHitMapper<?> projectionHitMapper, JsonObject hit,
8080
JsonObject source, ProjectionExtractContext context) {
81-
A accumulated = accumulator.createInitial();
81+
A accumulated = collector.createInitial();
8282

8383
E components = compositor.createInitial();
8484
for ( int i = 0; i < inners.length; i++ ) {
8585
Object extractedDataForInner = inners[i].extract( projectionHitMapper, hit, source, context );
8686
components = compositor.set( components, i, extractedDataForInner );
8787
}
88-
accumulated = accumulator.accumulate( accumulated, components );
88+
accumulated = collector.accumulate( accumulated, components );
8989

9090
return accumulated;
9191
}
9292

9393
@Override
9494
public final P transform(LoadingResult<?> loadingResult, A accumulated,
9595
ProjectionTransformContext context) {
96-
for ( int i = 0; i < accumulator.size( accumulated ); i++ ) {
97-
E transformedData = accumulator.get( accumulated, i );
96+
for ( int i = 0; i < collector.size( accumulated ); i++ ) {
97+
E transformedData = collector.get( accumulated, i );
9898
// Transform in-place
9999
for ( int j = 0; j < inners.length; j++ ) {
100100
Object extractedDataForInner = compositor.get( transformedData, j );
@@ -103,9 +103,9 @@ public final P transform(LoadingResult<?> loadingResult, A accumulated,
103103
transformedData = compositor.set( transformedData, j, transformedDataForInner );
104104
}
105105

106-
accumulated = accumulator.transform( accumulated, i, compositor.finish( transformedData ) );
106+
accumulated = collector.transform( accumulated, i, compositor.finish( transformedData ) );
107107
}
108-
return accumulator.finish( accumulated );
108+
return collector.finish( accumulated );
109109
}
110110
}
111111

@@ -119,14 +119,14 @@ static class Builder implements CompositeProjectionBuilder {
119119

120120
@Override
121121
public <E, V, P> SearchProjection<P> build(SearchProjection<?>[] inners, ProjectionCompositor<E, V> compositor,
122-
ProjectionAccumulator.Provider<V, P> accumulatorProvider) {
122+
ProjectionCollector.Provider<V, P> collectorProvider) {
123123
ElasticsearchSearchProjection<?>[] typedInners =
124124
new ElasticsearchSearchProjection<?>[inners.length];
125125
for ( int i = 0; i < inners.length; i++ ) {
126126
typedInners[i] = ElasticsearchSearchProjection.from( scope, inners[i] );
127127
}
128128
return new ElasticsearchCompositeProjection<>( this, typedInners,
129-
compositor, accumulatorProvider.get() );
129+
compositor, collectorProvider.get() );
130130
}
131131
}
132132
}

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/search/projection/impl/ElasticsearchDistanceToFieldProjection.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import org.hibernate.search.engine.backend.types.converter.spi.ProjectionConverter;
1919
import org.hibernate.search.engine.search.loading.spi.LoadingResult;
2020
import org.hibernate.search.engine.search.loading.spi.ProjectionHitMapper;
21-
import org.hibernate.search.engine.search.projection.ProjectionAccumulator;
21+
import org.hibernate.search.engine.search.projection.ProjectionCollector;
2222
import org.hibernate.search.engine.search.projection.SearchProjection;
2323
import org.hibernate.search.engine.search.projection.spi.DistanceToFieldProjectionBuilder;
2424
import org.hibernate.search.engine.spatial.DistanceUnit;
@@ -62,22 +62,22 @@ public class ElasticsearchDistanceToFieldProjection<A, P> extends AbstractElasti
6262
private final GeoPoint center;
6363
private final DistanceUnit unit;
6464

65-
private final ProjectionAccumulator<Double, Double, A, P> accumulator;
65+
private final ProjectionCollector<Double, Double, A, P> collector;
6666

6767
private final String scriptFieldName;
6868
private final ElasticsearchFieldProjection<?, Double, P, ?> sourceProjection;
6969

7070
private ElasticsearchDistanceToFieldProjection(Builder builder,
71-
ProjectionAccumulator.Provider<Double, P> accumulatorProvider,
72-
ProjectionAccumulator<Double, Double, A, P> accumulator) {
71+
ProjectionCollector.Provider<Double, P> collectorProvider,
72+
ProjectionCollector<Double, Double, A, P> collector) {
7373
super( builder );
7474
this.codec = builder.field.type().codec();
7575

7676
this.absoluteFieldPath = builder.field.absolutePath();
7777
this.singleValuedInRoot = !builder.field.multiValuedInRoot();
7878
this.center = builder.center;
7979
this.unit = builder.unit;
80-
this.accumulator = accumulator;
80+
this.collector = collector;
8181
if ( singleValuedInRoot && builder.field.nestedPathHierarchy().isEmpty() ) {
8282
// Rely on docValues when there is no sort to extract the distance from.
8383
scriptFieldName = createScriptFieldName( absoluteFieldPath, center );
@@ -88,7 +88,7 @@ private ElasticsearchDistanceToFieldProjection(Builder builder,
8888
scriptFieldName = null;
8989
this.sourceProjection = new ElasticsearchFieldProjection<>(
9090
builder.scope, builder.field,
91-
this::computeDistanceWithUnit, false, NO_OP_DOUBLE_CONVERTER, accumulatorProvider
91+
this::computeDistanceWithUnit, false, NO_OP_DOUBLE_CONVERTER, collectorProvider
9292
);
9393
}
9494
}
@@ -99,7 +99,7 @@ public String toString() {
9999
+ "absoluteFieldPath=" + absoluteFieldPath
100100
+ ", center=" + center
101101
+ ", unit=" + unit
102-
+ ", accumulator=" + accumulator
102+
+ ", collector=" + collector
103103
+ "]";
104104
}
105105

@@ -130,13 +130,13 @@ public A extract(ProjectionHitMapper<?> projectionHitMapper, JsonObject hit,
130130
Integer distanceSortIndex = singleValuedInRoot ? context.getDistanceSortIndex( absoluteFieldPath, center ) : null;
131131

132132
if ( distanceSortIndex != null ) {
133-
A accumulated = accumulator.createInitial();
134-
accumulated = accumulator.accumulate( accumulated, extractDistanceFromSortKey( hit, distanceSortIndex ) );
133+
A accumulated = collector.createInitial();
134+
accumulated = collector.accumulate( accumulated, extractDistanceFromSortKey( hit, distanceSortIndex ) );
135135
return accumulated;
136136
}
137137
else {
138-
A accumulated = accumulator.createInitial();
139-
accumulated = accumulator.accumulate( accumulated, extractDistanceFromScriptField( hit ) );
138+
A accumulated = collector.createInitial();
139+
accumulated = collector.accumulate( accumulated, extractDistanceFromScriptField( hit ) );
140140
return accumulated;
141141
}
142142
}
@@ -145,7 +145,7 @@ public A extract(ProjectionHitMapper<?> projectionHitMapper, JsonObject hit,
145145
public P transform(LoadingResult<?> loadingResult, A extractedData,
146146
ProjectionTransformContext context) {
147147
// Nothing to transform: we take the values as they are.
148-
return accumulator.finish( extractedData );
148+
return collector.finish( extractedData );
149149
}
150150

151151
private Double extractDistanceFromScriptField(JsonObject hit) {
@@ -255,9 +255,9 @@ public void unit(DistanceUnit unit) {
255255
}
256256

257257
@Override
258-
public <P> SearchProjection<P> build(ProjectionAccumulator.Provider<Double, P> accumulatorProvider) {
259-
return new ElasticsearchDistanceToFieldProjection<>( this, accumulatorProvider,
260-
accumulatorProvider.get() );
258+
public <P> SearchProjection<P> build(ProjectionCollector.Provider<Double, P> collectorProvider) {
259+
return new ElasticsearchDistanceToFieldProjection<>( this, collectorProvider,
260+
collectorProvider.get() );
261261
}
262262
}
263263
}

0 commit comments

Comments
 (0)