3
votes

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().

1
Checked out the source, seems it cannot be done.Nils Weinander

1 Answers

2
votes

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