@@ -223,18 +223,10 @@ private void processFilterAnnotation(List<IFilterBuilderHelper> classFilters, St
223
223
}
224
224
for (String path : paths ) {
225
225
path = path .trim ();
226
- boolean isAnalyzed = isAnalyzed (indexable );
227
- String nestedPath = indexable .getAnnotation (NestedObject .class ) == null ? null : esFieldName ;
228
- if (nestedPath == null ) {
229
- int nestedIndicator = esFieldName .lastIndexOf ("." );
230
- if (nestedIndicator > 0 ) {
231
- nestedPath = esFieldName .substring (0 , nestedIndicator );
232
- esFieldName = esFieldName .substring (nestedIndicator + 1 , esFieldName .length ());
233
- }
226
+ addFilter (classFilters , esFieldName , indexable , path , isAnalyzed (indexable , null ));
227
+ for (String alternateFieldName : alternateFieldNames (indexable )) {
228
+ addFilter (classFilters , alternateFieldName , indexable , path , isAnalyzed (indexable , alternateFieldName ));
234
229
}
235
- String filterPath = getFilterPath (path , esFieldName );
236
-
237
- classFilters .add (new TermsFilterBuilderHelper (isAnalyzed , nestedPath , filterPath ));
238
230
}
239
231
return ;
240
232
}
@@ -245,6 +237,20 @@ private void processFilterAnnotation(List<IFilterBuilderHelper> classFilters, St
245
237
}
246
238
}
247
239
240
+ private void addFilter (List <IFilterBuilderHelper > classFilters , String esFieldName , Indexable indexable , String path , boolean isAnalyzed ) {
241
+ String nestedPath = indexable .getAnnotation (NestedObject .class ) == null ? null : esFieldName ;
242
+ if (nestedPath == null ) {
243
+ int nestedIndicator = esFieldName .lastIndexOf ("." );
244
+ if (nestedIndicator > 0 ) {
245
+ nestedPath = esFieldName .substring (0 , nestedIndicator );
246
+ esFieldName = esFieldName .substring (nestedIndicator + 1 , esFieldName .length ());
247
+ }
248
+ }
249
+ String filterPath = getFilterPath (path , esFieldName );
250
+
251
+ classFilters .add (new TermsFilterBuilderHelper (isAnalyzed , nestedPath , filterPath ));
252
+ }
253
+
248
254
private void processFacetAnnotation (List <IFacetBuilderHelper > classFacets , List <IFilterBuilderHelper > classFilters , String esFieldName ,
249
255
Indexable indexable ) {
250
256
TermsFacet termsFacet = indexable .getAnnotation (TermsFacet .class );
@@ -263,17 +269,11 @@ private void processFacetAnnotation(List<IFacetBuilderHelper> classFacets, List<
263
269
}
264
270
for (String path : paths ) {
265
271
path = path .trim ();
266
- boolean isAnalyzed = isAnalyzed (indexable );
267
- String nestedPath = indexable .getAnnotation (NestedObject .class ) == null ? null : esFieldName ;
268
- String filterPath = getFilterPath (path , esFieldName );
269
-
270
- IFacetBuilderHelper facetBuilderHelper = new TermsAggregationBuilderHelper (isAnalyzed , nestedPath , filterPath , termsFacet );
271
- classFacets .add (facetBuilderHelper );
272
- if (classFilters .contains (facetBuilderHelper )) {
273
- classFilters .remove (facetBuilderHelper );
274
- LOGGER .warn ("Field <" + esFieldName + "> already had a filter that will be replaced by the defined facet. Only a single one is allowed." );
272
+
273
+ addAggregation (termsFacet , indexable , esFieldName , path , isAnalyzed (indexable , null ), classFacets , classFilters );
274
+ for (String alternateFieldName : alternateFieldNames (indexable )) {
275
+ addAggregation (termsFacet , indexable , alternateFieldName , path , isAnalyzed (indexable , alternateFieldName ), classFacets , classFilters );
275
276
}
276
- classFilters .add (facetBuilderHelper );
277
277
}
278
278
return ;
279
279
}
@@ -293,15 +293,50 @@ private String getFilterPath(String path, String esFieldName) {
293
293
return path .isEmpty () ? esFieldName : esFieldName + "." + path ;
294
294
}
295
295
296
- private boolean isAnalyzed (Indexable indexable ) {
296
+ private boolean isAnalyzed (Indexable indexable , String name ) {
297
297
boolean isAnalysed = true ;
298
+ StringFieldMulti multiAnnotation = indexable .getAnnotation (StringFieldMulti .class );
299
+ if (multiAnnotation != null ) {
300
+ if (name == null ) {
301
+ return IndexType .analyzed .equals (multiAnnotation .main ().indexType ());
302
+ } else {
303
+ for (int i = 0 ; i < multiAnnotation .multiNames ().length ; i ++) {
304
+ if (multiAnnotation .multiNames ()[i ].equals (name )) {
305
+ return IndexType .analyzed .equals (multiAnnotation .multi ()[i ].indexType ());
306
+ }
307
+ }
308
+ }
309
+ }
310
+
298
311
StringField stringFieldAnnotation = indexable .getAnnotation (StringField .class );
299
- if (stringFieldAnnotation != null && ! IndexType . analyzed . equals ( stringFieldAnnotation . indexType ()) ) {
300
- isAnalysed = false ;
312
+ if (stringFieldAnnotation != null ) {
313
+ return IndexType . analyzed . equals ( stringFieldAnnotation . indexType ()) ;
301
314
}
302
315
return isAnalysed ;
303
316
}
304
317
318
+ private void addAggregation (TermsFacet termsFacet , Indexable indexable , String esFieldName , String path , boolean isAnalyzed ,
319
+ List <IFacetBuilderHelper > classFacets , List <IFilterBuilderHelper > classFilters ) {
320
+ String nestedPath = indexable .getAnnotation (NestedObject .class ) == null ? null : esFieldName ;
321
+ String filterPath = getFilterPath (path , esFieldName );
322
+
323
+ IFacetBuilderHelper facetBuilderHelper = new TermsAggregationBuilderHelper (isAnalyzed , nestedPath , filterPath , termsFacet );
324
+ classFacets .add (facetBuilderHelper );
325
+ if (classFilters .contains (facetBuilderHelper )) {
326
+ classFilters .remove (facetBuilderHelper );
327
+ LOGGER .warn ("Field <" + esFieldName + "> already had a filter that will be replaced by the defined facet. Only a single one is allowed." );
328
+ }
329
+ classFilters .add (facetBuilderHelper );
330
+ }
331
+
332
+ private String [] alternateFieldNames (Indexable indexable ) {
333
+ StringFieldMulti multi = indexable .getAnnotation (StringFieldMulti .class );
334
+ if (multi == null ) {
335
+ return new String [0 ];
336
+ }
337
+ return multi .multiNames ();
338
+ }
339
+
305
340
private void processStringOrPrimitive (Class <?> clazz , Map <String , Object > propertiesDefinitionMap , String pathPrefix , Indexable indexable ) {
306
341
processFieldAnnotation (IndexName .class , new IndexNameAnnotationParser (), propertiesDefinitionMap , pathPrefix , indexable );
307
342
processFieldAnnotation (NullValue .class , new NullValueAnnotationParser (), propertiesDefinitionMap , pathPrefix , indexable );
0 commit comments