Skip to content

Commit 1e975f9

Browse files
Sannegunnarmorling
authored andcommitted
HSEARCH-1987 Deal with flexible prefixes in nested IndexedEmbedded Numeric fields
1 parent 121878b commit 1e975f9

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

engine/src/main/java/org/hibernate/search/engine/metadata/impl/AnnotationMetadataProvider.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ private void checkDocumentId(XProperty member,
172172
return;
173173
}
174174

175-
String attributeName = getIdAttributeName( member, idAnnotation );
176-
String path = prefix + attributeName;
175+
final String unprefixedAttributeName = getIdAttributeName( member, idAnnotation );
176+
final String path = prefix + unprefixedAttributeName;
177177
if ( isRoot ) {
178178
createIdPropertyMetadata(
179179
member,
@@ -182,7 +182,8 @@ private void checkDocumentId(XProperty member,
182182
configContext,
183183
parseContext,
184184
idAnnotation,
185-
path
185+
path,
186+
unprefixedAttributeName
186187
);
187188
}
188189
else {
@@ -237,7 +238,8 @@ private void createIdPropertyMetadata(XProperty member,
237238
ConfigContext configContext,
238239
ParseContext parseContext,
239240
Annotation idAnnotation,
240-
String path) {
241+
String path,
242+
String unprefixedAttributeName) {
241243
if ( parseContext.isExplicitDocumentId() ) {
242244
if ( idAnnotation instanceof DocumentId ) {
243245
throw log.duplicateDocumentIdFound( typeMetadataBuilder.getIndexedType().getName() );
@@ -251,7 +253,7 @@ private void createIdPropertyMetadata(XProperty member,
251253
parseContext.setExplicitDocumentId( true );
252254
}
253255

254-
NumericField numericFieldAnnotation = numericFields.getNumericFieldAnnotation( path );
256+
NumericField numericFieldAnnotation = numericFields.getNumericFieldAnnotation( unprefixedAttributeName );
255257

256258
// Don't apply @NumericField if it is given with the default name and there is another custom @Field
257259
if ( numericFieldAnnotation != null && numericFieldAnnotation.forField().isEmpty()
@@ -1013,7 +1015,8 @@ private void bindFieldAnnotation(
10131015
typeMetadataBuilder.disableStateInspectionOptimization();
10141016
}
10151017

1016-
String fieldName = prefix + ReflectionHelper.getAttributeName( member, fieldAnnotation.name() );
1018+
final String unPrefixedFieldName = ReflectionHelper.getAttributeName( member, fieldAnnotation.name() );
1019+
final String fieldName = prefix + unPrefixedFieldName;
10171020
Store store = fieldAnnotation.store();
10181021
Field.Index index = AnnotationProcessingHelper.getIndex(
10191022
fieldAnnotation.index(),
@@ -1022,7 +1025,7 @@ private void bindFieldAnnotation(
10221025
);
10231026
Field.TermVector termVector = AnnotationProcessingHelper.getTermVector( fieldAnnotation.termVector() );
10241027

1025-
NumericField numericFieldAnnotation = numericFields.getNumericFieldAnnotation( fieldName );
1028+
NumericField numericFieldAnnotation = numericFields.getNumericFieldAnnotation( unPrefixedFieldName );
10261029

10271030
FieldBridge fieldBridge = bridgeFactory.buildFieldBridge(
10281031
fieldAnnotation,

engine/src/main/java/org/hibernate/search/engine/metadata/impl/NumericFieldsConfiguration.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@ class NumericFieldsConfiguration {
5656
* Gets the {@code @NumericField} annotation matching the given field, if any. As a side-effect, the given field
5757
* is collected for later validation of configured numeric fields against actually present fields.
5858
*/
59-
NumericField getNumericFieldAnnotation(String fieldName) {
60-
fieldName = unqualify( fieldName );
59+
NumericField getNumericFieldAnnotation(final String unprefixedFieldName) {
60+
fieldsOfProperty.add( unprefixedFieldName );
6161

62-
fieldsOfProperty.add( fieldName );
63-
64-
NumericField numericFieldAnnotation = fieldsMarkedAsNumeric.get( fieldName );
62+
NumericField numericFieldAnnotation = fieldsMarkedAsNumeric.get( unprefixedFieldName );
6563

6664
if ( numericFieldAnnotation == null ) {
6765
numericFieldAnnotation = fieldsMarkedAsNumeric.get( "" );
@@ -89,12 +87,4 @@ void validate() {
8987
}
9088
}
9189

92-
private String unqualify(String fieldName) {
93-
int separatorIdx = fieldName.lastIndexOf( '.' );
94-
if ( separatorIdx != -1 ) {
95-
fieldName = fieldName.substring( separatorIdx + 1 );
96-
}
97-
98-
return fieldName;
99-
}
10090
}

0 commit comments

Comments
 (0)