Skip to content

Commit 9b7b0fb

Browse files
marko-bekhtayrodiere
authored andcommitted
HSEARCH-5021 Remove the array check from a vector DefaultInitiator
1 parent ed82795 commit 9b7b0fb

File tree

3 files changed

+9
-26
lines changed

3 files changed

+9
-26
lines changed

integrationtest/mapper/pojo-base/src/test/java/org/hibernate/search/integrationtest/mapper/pojo/mapping/definition/VectorFieldIT.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -345,15 +345,9 @@ class IndexedEntity {
345345
.satisfies( FailureReportUtils.hasFailureReport()
346346
.typeContext( IndexedEntity.class.getName() )
347347
.pathContext( ".notVector" )
348-
.failure(
349-
"Unable to apply property mapping: this property mapping must target an index field of vector type",
350-
"but the resolved field type is non-vector",
351-
"This generally means you need to use a different field annotation"
352-
+ " or to convert property values using a custom ValueBridge or ValueBinder",
353-
"If you are already using a custom ValueBridge or ValueBinder, check its field type",
354-
"encountered type DSL step '",
355-
"expected interface '" + VectorFieldTypeOptionsStep.class.getName() + "'"
356-
) );
348+
// NOTE: this is an exception from the IndexFieldTypeFactory implementation, hence it is backend-specific and in this case
349+
// it is from the stub-backend.
350+
.failure( "No built-in vector index field type for class: 'java.lang.Integer'." ) );
357351
}
358352

359353
@Test
@@ -371,14 +365,9 @@ class IndexedEntity {
371365
.satisfies( FailureReportUtils.hasFailureReport()
372366
.typeContext( IndexedEntity.class.getName() )
373367
.pathContext( ".bytes" )
374-
.failure(
375-
"Unable to apply property mapping: this property mapping must target an index field of vector type, but the resolved field type is non-vector",
376-
"This generally means you need to use a different field annotation"
377-
+ " or to convert property values using a custom ValueBridge or ValueBinder",
378-
"If you are already using a custom ValueBridge or ValueBinder, check its field type",
379-
"encountered type DSL step '",
380-
"expected interface '" + VectorFieldTypeOptionsStep.class.getName() + "'"
381-
) );
368+
// NOTE: this is an exception from the IndexFieldTypeFactory implementation, hence it is backend-specific and in this case
369+
// it is from the stub-backend.
370+
.failure( "No built-in vector index field type for class: 'java.lang.Integer'." ) );
382371
}
383372

384373
@Test

mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/mapping/definition/programmatic/impl/PropertyMappingVectorFieldOptionsStepImpl.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,7 @@ public <F> IndexFieldTypeOptionsStep<?, F> initiate(IndexFieldTypeFactory factor
3636
if ( dimension == null ) {
3737
throw log.vectorDimensionNotSpecified();
3838
}
39-
// we consider arrays (byte[] and float[] in particular to be vector types, anything else will be
40-
// treated as a non-vector field and delegated to a regular as(..) call.
41-
if ( clazz.isArray() ) {
42-
return factory.asVector( dimension, clazz );
43-
}
44-
else {
45-
return factory.as( clazz );
46-
}
39+
return factory.asVector( dimension, clazz );
4740
}
4841
},
4942
FieldModelContributorContext::vectorTypeOptionsStep );

util/internal/integrationtest/common/src/main/java/org/hibernate/search/util/impl/integrationtest/common/stub/backend/types/dsl/impl/StubIndexFieldTypeFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.hibernate.search.engine.backend.types.dsl.VectorFieldTypeOptionsStep;
2828
import org.hibernate.search.engine.mapper.mapping.building.spi.IndexFieldTypeDefaultsProvider;
2929
import org.hibernate.search.engine.spatial.GeoPoint;
30+
import org.hibernate.search.util.common.SearchException;
3031

3132
public class StubIndexFieldTypeFactory implements IndexFieldTypeFactory {
3233

@@ -167,7 +168,7 @@ public <F> VectorFieldTypeOptionsStep<?, F> asVector(int dimension, Class<F> val
167168
if ( float[].class.equals( valueType ) ) {
168169
return (VectorFieldTypeOptionsStep<?, F>) asFloatVector( dimension );
169170
}
170-
return new StubVectorFieldTypeOptionsStep<>( dimension, valueType );
171+
throw new SearchException( "No built-in vector index field type for class: '" + valueType.getName() + "'." );
171172
}
172173

173174
@Override

0 commit comments

Comments
 (0)