gpt4 book ai didi

Hibernate Search Filter 没有使用 Enum 的预期结果

转载 作者:行者123 更新时间:2023-12-02 00:32:09 25 4
gpt4 key购买 nike

我正在使用 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 个结果,尽管应该有几十个。

有从哪里开始的想法吗?

最佳答案

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

我需要改变

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

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

关于Hibernate Search Filter 没有使用 Enum 的预期结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6350909/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com