[英]Indexing an Enum type field with hibernate-search
I am having problems searching using Hibernate search when the index I want to use is of an Enum type. 当我要使用的索引为Enum类型时,使用Hibernate搜索进行搜索时遇到问题。
Here is an example of what my application looks like: 这是我的应用程序外观的一个示例:
@Entity
@Indexed
public class MyEntity{
@Id
@Field
public Long id;
@Field(bridge=@FieldBridge(impl=EnumBridge.class))
public Flavour flavour;
}
with 同
public enum Flavour {
vanilla,
chocolate,
strawberry,
pistacchio;
}
Then I try to find all instances using this type of query. 然后,我尝试使用这种类型的查询查找所有实例。
QueryBuilder qb = [~] ;
Query q = qb.keyword().onField("flavour").matching(Flavour.vanilla).createQuery();
When I test this the results always comes empty. 当我测试此结果总是空的。 I even tried to see the content of the indexes using Luke and I do not seem to find "flavour".
我什至试图使用Luke来查看索引的内容,但似乎没有发现“味道”。 I do re-index everything after committing changes.
提交更改后,我会为所有内容重新编制索引。 Everyother type of indexing works and querying works perfectly on anything but enum fields.
除枚举字段外,其他所有类型的索引都可以工作,查询也可以完美地工作。
I have tried almost any combination of the norms
, analyze
, index
, store
, ... of the @Field
annotation (I am using Hibernate-search 4.5.x with hibernate 4.3.1). 我已经尝试了
@Field
批注的norms
, analyze
, index
, store
,...的几乎任何组合(我在使用Hibernate 4.3.1和Hibernate-search 4.5.x)。
What am I doing wrong? 我究竟做错了什么? Any settings I should be looking at?
我应该查看任何设置吗? Any help is welcome.
欢迎任何帮助。
The entity seems to store the flavour using the ordinal (so the column flavour contains 0 instead of "vanilla"). 实体似乎使用序数存储了味道(因此列味道包含0而不是“香草”)。
I don't know, what the EnumBridge is doing, but I would suggest to store the enumeration as a string: 我不知道EnumBridge在做什么,但是我建议将枚举存储为字符串:
@Entity
@Indexed
public class MyEntity{
@Id
@Field
public Long id;
@Field(bridge=@FieldBridge(impl=EnumBridge.class))
@Enumerated(EnumType.STRING)
public Flavour flavour;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.