Index multiple properties in the same field

Hi @yrodiere ,

I was using hibernatesearch 5 earlier and now i migrated to hibernate 6 , so everything is working fine , but the way _all was configured earlier in hibernate 5 , is now not allowed in 6 why ? please help this feature is required

@Entity(name = Country.TABLE_NAME)
@Indexed(index = “ind_country”)
public class Country {

public static final String TABLE_NAME = "tbl_country";

public static final String ID_COLUMN = "id";

private static final String NAME_COLUMN ="name";

private static final String A2_CODE_COLUMN ="a2_code";

@Id
@Column(name=ID_COLUMN, nullable = false,length = 63)
private String id;

@Column(name = NAME_COLUMN,  length = 63)
@FullTextField(name="name")
@FullTextField(name="ALL") - was working earlier using @Field 
private String name;

@Column(name = A2_CODE_COLUMN,  length = 2)
@FullTextField(name="a2_code")
@FullTextField(name="ALL")
private String a2Code;

iam getting below exception
- HSEARCH400520: Duplicate index field definition: ‘ALL’.
Index field names must be unique.
Look for two property mappings with the same field name,
or two indexed-embeddeds with prefixes that lead to conflicting index field names,
or two custom bridges declaring index fields with the same name.

Hibernate Search 6 pays more attention to the fields you declare, what their capabilities are (single-valued or multi-valued in particular) and whether there are duplicates or not. As a result, for now, it doesn’t allow two properties to declare a field with the same name (in your case, ALL). This might get solved (in a way) once we introduce the ability to apply “labels” to fields with different names (HSEARCH-3926).

In the meantime, the easiest way to to what you want is to introduce a transient getter that declares the ALL field and returns all the values you want to assign to that field:

public static final String TABLE_NAME = "tbl_country";

public static final String ID_COLUMN = "id";

private static final String NAME_COLUMN ="name";

private static final String A2_CODE_COLUMN ="a2_code";

@Id
@Column(name=ID_COLUMN, nullable = false,length = 63)
private String id;

@Column(name = NAME_COLUMN,  length = 63)
@FullTextField(name="name")
private String name;

@Column(name = A2_CODE_COLUMN,  length = 2)
@FullTextField(name="a2_code")
private String a2Code;

@javax.persistence.Transient
@FullTextField(name="ALL")
@IndexingDependency(derivedFrom = {
        @ObjectPath(@PropertyValue(propertyName = "name")),
        @ObjectPath(@PropertyValue(propertyName = "a2Code"))
})
public List<String> getAll() {
    return Arrays.asList(name, a2Code);
}

Alternatively, you should be able to achieve the same result (and more) using a type bridge, but that solution will be more complex.