开发者

Hibernate Search Filter not having expected results with Enum

开发者 https://www.devze.com 2023-03-13 12:25 出处:网络
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

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().objec开发者_如何转开发tToString(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?


Thanks to the help of some people in the hibernate forum I was able to fix the problem.

I needed to change

@Field(name = "coursestatus", index = Index.TOKENIZED, store = Store.YES)

to

@Field(name = "coursestatus", index = Index.UN_TOKENIZED, store = Store.YES)
0

精彩评论

暂无评论...
验证码 换一张
取 消