Hibernate 搜索过滤器没有使用 Enum 获得预期结果

发布于 2024-11-15 14:15:25 字数 1922 浏览 1 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝戈者 2024-11-22 14:15:25

感谢 hibernate 论坛中一些人的帮助 我能够解决这个问题。

我需要更改

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

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

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文