Hibernate 搜索过滤器没有使用 Enum 获得预期结果
我正在使用 hibernate search 3.4,并且遇到了一个小问题。我尝试使用一个过滤器 (CourseStatusFilterFactory
),但每次启用它时,都不会返回任何结果。我有另一个可以正常工作的过滤器 (DeletedFilterFactory
),所以我不确定问题是什么。
这是我试图搜索的对象:
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Indexed
@FullTextFilterDefs({
@FullTextFilterDef(name = "statusFilter", impl = CourseStatusFilterFactory.class, cache = FilterCacheModeType.NONE),
@FullTextFilterDef(name = "deletedCourse", impl = DeletedFilterFactory.class, cache = FilterCacheModeType.NONE)})
public class Course extends LightEntity implements Serializable {
private static final long serialVersionUID = 21L;
@Id
@DocumentId
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Field(name = "title", index = Index.TOKENIZED, store = Store.YES)
private String title;
@Field(name = "coursestatus", index = Index.TOKENIZED, store = Store.YES)
@Enumerated(EnumType.STRING)
private CourseStatus status;}
Any my FilterFactory:
public class CourseStatusFilterFactory {
private CourseStatus status;
public void setStatus(CourseStatus status) {
this.status = status;
}
@Key
public FilterKey getKey() {
StandardFilterKey key = new StandardFilterKey();
key.addParameter(status);
return key;
}
@Factory
public Filter getFilter() {
String statusString = new EnumBridge().objectToString(this.status);
Query query = new TermQuery(new Term("coursestatus", statusString));
CachingWrapperFilter cachingWrapperFilter = new CachingWrapperFilter(new QueryWrapperFilter(query));
return cachingWrapperFilter;
}}
并启用我的过滤器:
persistenceQuery.enableFullTextFilter("statusFilter").setParameter("status", CourseStatus.PUBLISHED);
调试代码时,我可以看到过滤器中的查询确实设置为“coursestatus:PUBLISHED”,但我仍然有 0 个结果,尽管应该有几十个。
有什么想法从哪里开始吗?
I'm using hibernate search 3.4, and I'm running in to a small problem. I have a filter I'm attempting to use (CourseStatusFilterFactory
), but every time I enable it, no results are returned. I have another filter that works without issues (DeletedFilterFactory
), so I'm not sure what the problem is.
Here is the object I am trying to search:
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Indexed
@FullTextFilterDefs({
@FullTextFilterDef(name = "statusFilter", impl = CourseStatusFilterFactory.class, cache = FilterCacheModeType.NONE),
@FullTextFilterDef(name = "deletedCourse", impl = DeletedFilterFactory.class, cache = FilterCacheModeType.NONE)})
public class Course extends LightEntity implements Serializable {
private static final long serialVersionUID = 21L;
@Id
@DocumentId
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Field(name = "title", index = Index.TOKENIZED, store = Store.YES)
private String title;
@Field(name = "coursestatus", index = Index.TOKENIZED, store = Store.YES)
@Enumerated(EnumType.STRING)
private CourseStatus status;}
Any my FilterFactory:
public class CourseStatusFilterFactory {
private CourseStatus status;
public void setStatus(CourseStatus status) {
this.status = status;
}
@Key
public FilterKey getKey() {
StandardFilterKey key = new StandardFilterKey();
key.addParameter(status);
return key;
}
@Factory
public Filter getFilter() {
String statusString = new EnumBridge().objectToString(this.status);
Query query = new TermQuery(new Term("coursestatus", statusString));
CachingWrapperFilter cachingWrapperFilter = new CachingWrapperFilter(new QueryWrapperFilter(query));
return cachingWrapperFilter;
}}
and to enable my filter:
persistenceQuery.enableFullTextFilter("statusFilter").setParameter("status", CourseStatus.PUBLISHED);
When debugging the code, I can see that my query in the filter does get set to "coursestatus:PUBLISHED", but I still have 0 results, even though there should be dozens.
Any ideas of where to start?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢 hibernate 论坛中一些人的帮助 我能够解决这个问题。
我需要更改
为
Thanks to the help of some people in the hibernate forum I was able to fix the problem.
I needed to change
to