@@ -107,8 +107,7 @@ public static Object[] getDocumentFields(ExtendedSearchIntegrator extendedIntegr
107
107
}
108
108
}
109
109
110
- final TypeMetadata metadata = builderIndexedEntity .getMetadata ();
111
- processFieldsForProjection ( metadata , fields , result , document , conversionContext );
110
+ processFieldsForProjection ( builderIndexedEntity , fields , result , document , conversionContext );
112
111
return result ;
113
112
}
114
113
@@ -138,7 +137,28 @@ public static void populateResult(String fieldName,
138
137
}
139
138
}
140
139
141
- private static void processFieldsForProjection (TypeMetadata typeMetadata , String [] fields , Object [] result , Document document , ConversionContext contextualBridge ) {
140
+ private static void processFieldsForProjection (DocumentBuilderIndexedEntity builderIndexedEntity , String [] fields , Object [] result , Document document , ConversionContext conversionContext ) {
141
+ final TypeMetadata metadata = builderIndexedEntity .getMetadata ();
142
+
143
+ //First try setting each projected field considering mapping metadata to apply (inverse) field bridges:
144
+ processMetadataRecursivelyForProjections ( metadata , fields , result , document , conversionContext );
145
+
146
+ //If we still didn't know the value using any bridge, return the raw value or string:
147
+ //Important: make sure this happens as last step of projections! See also HSEARCH-1786
148
+ for ( int index = 0 ; index < result .length ; index ++ ) {
149
+ if ( result [index ] == NOT_SET ) {
150
+ result [index ] = null ; // make sure we never return NOT_SET
151
+ if ( document != null ) {
152
+ IndexableField field = document .getField ( fields [index ] );
153
+ if ( field != null ) {
154
+ result [index ] = extractObjectFromFieldable ( field );
155
+ }
156
+ }
157
+ }
158
+ }
159
+ }
160
+
161
+ private static void processMetadataRecursivelyForProjections (TypeMetadata typeMetadata , String [] fields , Object [] result , Document document , ConversionContext contextualBridge ) {
142
162
//process base fields
143
163
for ( PropertyMetadata propertyMetadata : typeMetadata .getAllPropertyMetadata () ) {
144
164
for ( DocumentFieldMetadata fieldMetadata : propertyMetadata .getFieldMetadata () ) {
@@ -170,7 +190,7 @@ private static void processFieldsForProjection(TypeMetadata typeMetadata, String
170
190
if ( embeddedTypeMetadata .getEmbeddedContainer () == EmbeddedTypeMetadata .Container .OBJECT ) {
171
191
contextualBridge .pushProperty ( embeddedTypeMetadata .getEmbeddedFieldName () );
172
192
try {
173
- processFieldsForProjection (
193
+ processMetadataRecursivelyForProjections (
174
194
embeddedTypeMetadata , fields , result , document , contextualBridge
175
195
);
176
196
}
@@ -195,19 +215,6 @@ private static void processFieldsForProjection(TypeMetadata typeMetadata, String
195
215
);
196
216
}
197
217
}
198
-
199
- //If we still didn't know the value using any bridge, return the raw value or string:
200
- for ( int index = 0 ; index < result .length ; index ++ ) {
201
- if ( result [index ] == NOT_SET ) {
202
- result [index ] = null ; // make sure we never return NOT_SET
203
- if ( document != null ) {
204
- IndexableField field = document .getField ( fields [index ] );
205
- if ( field != null ) {
206
- result [index ] = extractObjectFromFieldable ( field );
207
- }
208
- }
209
- }
210
- }
211
218
}
212
219
213
220
/**
0 commit comments