Nils Weinander
Nils Weinander

Reputation: 2141

Hibernate Search field mapping

The Hibernate Search @Field annotation gives the option to choose index name for a property:

...
@Field(name="somethingOrOther")
public String getSomeValue() {
...

The user guide says this about the name property of the @Field annotation:

name : describe under which name, the property should be stored in the Lucene Document. The default value is the property name (following the JavaBeans convention)

Is there any way to set the name to another value from the annotated bean?

Something like

...
public String getFieldName() {
   return fieldName;
}

@Field(name="{fieldName}")
public String getFieldValue() {
   return fieldValue;
}

where {fieldName} will be replaced with the result of getFieldName().

Upvotes: 3

Views: 1154

Answers (1)

Sanne
Sanne

Reputation: 6107

It can be done using a custom FieldBridge. When implementing the FieldBridge interface your own code is responsible for adding the value to the Lucene Document, so in practice you can write whatever you want.

FieldBridge documentation

Upvotes: 2

Related Questions