Skip to content

Commit 0ed9939

Browse files
committed
HSEARCH-4577 Some cleanups
1 parent 1c3e61a commit 0ed9939

File tree

40 files changed

+143
-159
lines changed

40 files changed

+143
-159
lines changed

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

Lines changed: 1 addition & 1 deletion
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 '.multi()' when you create the projection.")
605+
+ " Make sure to call '.accumulator(...)' when you create the projection.")
606606
SearchException invalidSingleValuedProjectionOnMultiValuedField(String absolutePath, @Param EventContext context);
607607

608608
@Message(id = ID_OFFSET + 117,

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/search/query/dsl/impl/ElasticsearchSearchQuerySelectStepImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public <P> ElasticsearchSearchQueryWhereStep<P, LOS> select(SearchProjection<P>
8383
public ElasticsearchSearchQueryWhereStep<List<?>, LOS> select(SearchProjection<?>... projections) {
8484
return select( scope.projectionBuilders().composite()
8585
.build( projections, ProjectionCompositor.fromList( projections.length ),
86-
ProjectionAccumulator.single() ) );
86+
ProjectionAccumulator.nullable() ) );
8787
}
8888

8989
@Override

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ SearchException invalidFieldValueType(@FormatWith(ClassFormatter.class) Class<?>
537537
@Message(id = ID_OFFSET + 131,
538538
value = "Invalid cardinality for projection on field '%1$s': the projection is single-valued,"
539539
+ " but this field is multi-valued."
540-
+ " Make sure to call '.multi()' when you create the projection.")
540+
+ " Make sure to call '.accumulator(...)' when you create the projection.")
541541
SearchException invalidSingleValuedProjectionOnMultiValuedField(String absolutePath, @Param EventContext context);
542542

543543
@Message(id = ID_OFFSET + 135,
@@ -600,9 +600,9 @@ SearchException invalidContextForProjectionOnField(String absolutePath,
600600
value = "Invalid cardinality for projection on field '%1$s': the projection is single-valued,"
601601
+ " but this field is effectively multi-valued in this context,"
602602
+ " because parent object field '%2$s' is multi-valued."
603-
+ " Either call '.multi()' when you create the projection on field '%1$s',"
603+
+ " Either call '.accumulator(...)' when you create the projection on field '%1$s',"
604604
+ " or wrap that projection in an object projection like this:"
605-
+ " 'f.object(\"%2$s\").from(<the projection on field %1$s>).as(...).multi()'.")
605+
+ " 'f.object(\"%2$s\").from(<the projection on field %1$s>).as(...).accumulator(...)'.")
606606
SearchException invalidSingleValuedProjectionOnValueFieldInMultiValuedObjectField(String absolutePath,
607607
String objectFieldAbsolutePath);
608608

backend/lucene/src/main/java/org/hibernate/search/backend/lucene/search/query/dsl/impl/LuceneSearchQuerySelectStepImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public <P> LuceneSearchQueryWhereStep<P, LOS> select(SearchProjection<P> project
8181
public LuceneSearchQueryWhereStep<List<?>, LOS> select(SearchProjection<?>... projections) {
8282
return select( scope.projectionBuilders().composite()
8383
.build( projections, ProjectionCompositor.fromList( projections.length ),
84-
ProjectionAccumulator.single() ) );
84+
ProjectionAccumulator.nullable() ) );
8585
}
8686

8787
@Override

engine/src/main/java/org/hibernate/search/engine/search/projection/ProjectionAccumulator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
*/
4040
public interface ProjectionAccumulator<E, V, A, R> {
4141

42-
static <V> ProjectionAccumulator.Provider<V, V> single() {
43-
return BuiltInProjectionAccumulators.single();
42+
static <V> ProjectionAccumulator.Provider<V, V> nullable() {
43+
return BuiltInProjectionAccumulators.nullable();
4444
}
4545

4646
static <V> Provider<V, List<V>> list() {

engine/src/main/java/org/hibernate/search/engine/search/projection/definition/spi/ConstantProjectionDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static <T> BeanHolder<ConstantProjectionDefinition<List<T>>> emptyList()
5454
public static <T> BeanHolder<ConstantProjectionDefinition<T>> empty(ProjectionAccumulator.Provider<?, T> accumulator) {
5555
T empty = accumulator.get().empty();
5656

57-
if ( ProjectionAccumulator.single().equals( accumulator ) ) {
57+
if ( ProjectionAccumulator.nullable().equals( accumulator ) ) {
5858
return nullValue();
5959
}
6060
if ( ProjectionAccumulator.optional().equals( accumulator ) ) {

engine/src/main/java/org/hibernate/search/engine/search/projection/dsl/CompositeProjectionValueStep.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ public interface CompositeProjectionValueStep<N extends CompositeProjectionOptio
3737
* @deprecated Use {@link #accumulator(ProjectionAccumulator.Provider)} instead.
3838
*/
3939
@Deprecated(since = "8.0")
40-
CompositeProjectionOptionsStep<?, List<T>> multi();
40+
default CompositeProjectionOptionsStep<?, List<T>> multi() {
41+
return accumulator( ProjectionAccumulator.list() );
42+
}
4143

4244
/**
4345
* Defines how to accumulate composite projection values.

engine/src/main/java/org/hibernate/search/engine/search/projection/dsl/DistanceToFieldProjectionValueStep.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ public interface DistanceToFieldProjectionValueStep<N extends DistanceToFieldPro
3434
* @deprecated Use {@link #accumulator(ProjectionAccumulator.Provider)} instead.
3535
*/
3636
@Deprecated(since = "8.0")
37-
DistanceToFieldProjectionOptionsStep<?, List<T>> multi();
37+
default DistanceToFieldProjectionOptionsStep<?, List<T>> multi() {
38+
return accumulator( ProjectionAccumulator.list() );
39+
}
3840

3941
/**
4042
* Defines how to accumulate distance projection values.

engine/src/main/java/org/hibernate/search/engine/search/projection/dsl/FieldProjectionValueStep.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ public interface FieldProjectionValueStep<N extends FieldProjectionOptionsStep<?
3434
* @deprecated Use {@link #accumulator(ProjectionAccumulator.Provider)} instead.
3535
*/
3636
@Deprecated(since = "8.0")
37-
FieldProjectionOptionsStep<?, List<T>> multi();
37+
default FieldProjectionOptionsStep<?, List<T>> multi() {
38+
return accumulator( ProjectionAccumulator.list() );
39+
}
3840

3941
/**
4042
* Defines how to accumulate field projection values.

engine/src/main/java/org/hibernate/search/engine/search/projection/dsl/impl/CompositeProjectionValueStepImpl.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
*/
55
package org.hibernate.search.engine.search.projection.dsl.impl;
66

7-
import java.util.List;
8-
97
import org.hibernate.search.engine.search.projection.ProjectionAccumulator;
108
import org.hibernate.search.engine.search.projection.SearchProjection;
119
import org.hibernate.search.engine.search.projection.dsl.CompositeProjectionOptionsStep;
@@ -19,12 +17,7 @@ public class CompositeProjectionValueStepImpl<T>
1917

2018
public CompositeProjectionValueStepImpl(CompositeProjectionBuilder builder,
2119
SearchProjection<?>[] inners, ProjectionCompositor<?, T> compositor) {
22-
super( builder, inners, compositor, ProjectionAccumulator.single() );
23-
}
24-
25-
@Override
26-
public CompositeProjectionOptionsStep<?, List<T>> multi() {
27-
return accumulator( ProjectionAccumulator.list() );
20+
super( builder, inners, compositor, ProjectionAccumulator.nullable() );
2821
}
2922

3023
@Override

0 commit comments

Comments
 (0)