3

I'm trying to integrate Hibernate Search into an application. The application entities can have multiple properties that are stored multilingual. This is accomplished by splitting the non multilingual and multilingual properties into seperate entities. An example snippet of this split looks like this (ommitted hibernate annotations as the database part is working fine):

@Indexed
public class Assignment {

    @DocumentId
    private UUID id;

    @IndexedEmbedded
    private Map<String, AssignmentI18n> i18n;

    // Other properties
}

public class AssignmentI18n {

    @DocumentId
    @FieldBridge(impl = AssignmentI18nBridge.class)
    private AssignmentI18nId id;

    @Field
    private String title;

    @Field
    private String description;

    @Field
    private String requirements;

    public static class AssignmentI18nId {

        private UUID assignmentId;

        private String iso;
    }
}

Now I would like to make this data searchable using Hibernate Search by treating it as a single entity in the index. The way the annotations are set up this happens however all entries of the multilingual fields are stored in the same field in the index. Basicly my index structure looks like this:

id
i18n.title
i18n.description
i18n.requirements

As all values of the multilingual data are indexed in the same field I can no longer distinguish what language they belong to. Is there a way to make the index look more like this?:

id
i18n.nl.title
i18n.en.title
i18n.nl.description
i18n.en.description
i18n.nl.requirements
i18n.en.requirements

Basicly I would like to add the HashMap key value to the index field name. I've looked into the possibiliy of treating the map as a field with a custom FieldBridge but that doesn't seem like the correct approach.

René Kamp
  • 139
  • 3

1 Answers1

1

If you want to make the indexed fields look like the one you describe, use a custom field bridge. That's how you could get this structure, but since your map value is quite complex it would take quite a lot of custom code to create all fields.

You could create a feature request for Hibernate Search here. I could imagine that this type of feature would be of general use. Basically a way to either via an @IndexedEmbedded option or via an additional annotation define how the map key becomes part of the Lucene field name. That said, have you thought about how exactly you would then search in this index? Does the user somehow specify a locale and depending on this local you would target the appropriate fields? Also, how do you deal in your approach to configure different stemmers depending on the language type?

Hardy
  • 18,659
  • 3
  • 49
  • 65
  • I guess a FieldBridge it is then. I don't think the structure of the map is too complex though as all values will be of type String otherwise there no reason for them to be part of the multilingual object. I guess I could make a custom annotation to recognize which fields to add to the index. About your other questions, I'm currently taking this one step at a time and my first step is to create a suitable index. For now it only needed to search a single language at a time. Options like stemming and other filters have to be looked into though. – René Kamp Nov 06 '15 at 08:21