Hibernate Search 6 用多个关键字搜索多个字段
Hibernate Search 6 search multiple fields with multiple keywords
我想搜索这 2 个不同的变量:
@Enumerated(EnumType.STRING)
@Column(length = 20)
@Convert(converter = WorksEnumConverter.class)
@GenericField(valueBridge = @ValueBridgeRef(type = WorksValueBridge.class))
private WorksEnum works;
@Convert(converter = AcquisitionTypeConverter.class)
@Enumerated(EnumType.STRING)
@Column(length = 10)
@GenericField(valueBridge = @ValueBridgeRef(type = AcquisitionTypeBridge.class))
private AcquisitionTypeEnum acquisitionType;
如您所见,有两种类型的枚举,我想使用休眠搜索通过多个关键字进行搜索,我使用了桥接器和转换器,但总是出现无法将字符串转换为枚举的错误
这是我的休眠搜索实现代码:
if (requestSearchCustomer.getKeyword() != null) {
final String[] keywords = requestSearchCustomer.getKeyword().split(",");
final SearchPredicate keywordPredicate = getSearchScope().predicate().terms()
.fields(RequestDB_.WORKS, RequestDB_.ACQUISITION_TYPE)
.matchingAny(keywords).toPredicate();
predicate.must(keywordPredicate);
}
如果您想传递字符串,而不是 Hibernate Search 期望的枚举类型,您将需要禁用 Hibernate Search 的自动转换:
if (requestSearchCustomer.getKeyword() != null) {
final String[] keywords = requestSearchCustomer.getKeyword().split(",");
final SearchPredicate keywordPredicate = getSearchScope().predicate().terms()
.fields(RequestDB_.WORKS, RequestDB_.ACQUISITION_TYPE)
.matchingAny(Arrays.asList(keywords), ValueConvert.NO).toPredicate();
predicate.must(keywordPredicate);
}
见https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#search-dsl-argument-type
我想搜索这 2 个不同的变量:
@Enumerated(EnumType.STRING)
@Column(length = 20)
@Convert(converter = WorksEnumConverter.class)
@GenericField(valueBridge = @ValueBridgeRef(type = WorksValueBridge.class))
private WorksEnum works;
@Convert(converter = AcquisitionTypeConverter.class)
@Enumerated(EnumType.STRING)
@Column(length = 10)
@GenericField(valueBridge = @ValueBridgeRef(type = AcquisitionTypeBridge.class))
private AcquisitionTypeEnum acquisitionType;
如您所见,有两种类型的枚举,我想使用休眠搜索通过多个关键字进行搜索,我使用了桥接器和转换器,但总是出现无法将字符串转换为枚举的错误 这是我的休眠搜索实现代码:
if (requestSearchCustomer.getKeyword() != null) {
final String[] keywords = requestSearchCustomer.getKeyword().split(",");
final SearchPredicate keywordPredicate = getSearchScope().predicate().terms()
.fields(RequestDB_.WORKS, RequestDB_.ACQUISITION_TYPE)
.matchingAny(keywords).toPredicate();
predicate.must(keywordPredicate);
}
如果您想传递字符串,而不是 Hibernate Search 期望的枚举类型,您将需要禁用 Hibernate Search 的自动转换:
if (requestSearchCustomer.getKeyword() != null) {
final String[] keywords = requestSearchCustomer.getKeyword().split(",");
final SearchPredicate keywordPredicate = getSearchScope().predicate().terms()
.fields(RequestDB_.WORKS, RequestDB_.ACQUISITION_TYPE)
.matchingAny(Arrays.asList(keywords), ValueConvert.NO).toPredicate();
predicate.must(keywordPredicate);
}
见https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#search-dsl-argument-type