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:
Code:
@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(index = Index.TOKENIZED)
@FieldBridge(impl=EnumBridge.class)
@Enumerated(EnumType.STRING)
private CourseStatus status;}
The enum:
Code:
public enum CourseStatus {
DRAFT, PUBLISHED, INACTIVE;
}
Any my FilterFactory:
Code:
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("status", statusString));
CachingWrapperFilter cachingWrapperFilter = new CachingWrapperFilter(new QueryWrapperFilter(query));
return cachingWrapperFilter;
}}
and to enable my filter:
Code:
persistenceQuery.enableFullTextFilter("statusFilter").setParameter("status", CourseStatus.PUBLISHED);
When debugging the code, I can see that my query in the filter does get set to "status:PUBLISHED", but I still have 0 results, even though there should be dozens.
Any ideas of where to start?