我正在使用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;}
任何我的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个结果,即使应该有几十个。
任何从哪里开始的想法?
答案 0 :(得分:3)
感谢hibernate forum中某些人的帮助,我能够解决问题。
我需要改变
@Field(name = "coursestatus", index = Index.TOKENIZED, store = Store.YES)
到
@Field(name = "coursestatus", index = Index.UN_TOKENIZED, store = Store.YES)