【发布时间】:2015-08-01 05:29:28
【问题描述】:
以下是实体中定义的两个字段
@Column(name = "min_price")
@Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
@NumericField
@FieldBridge(impl = IntegerBridge.class)
private Integer minPrice;
@Column(name = "max_price")
@Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
@NumericField
@FieldBridge(impl = IntegerBridge.class)
private Integer maxPrice;
使用 entityManager 生成全文查询,如下所示
BooleanJunction priceBooleanJunction = queryBuilder.bool();
//Building range query for price
if (minPrice != null) {
Query rangeQueryMinPrice = queryBuilder.range().onField("minPrice").above(minPrice).createQuery();
priceBooleanJunction.must(rangeQueryMinPrice);
}
if (maxPrice != null) {
Query rangeQueryMaxPrice = queryBuilder.range().onField("maxPrice").below(maxPrice).createQuery();
priceBooleanJunction.must(rangeQueryMaxPrice);
}
BooleanJunction combainedBoolean = queryBuilder.bool();
if (!priceBooleanJunction.isEmpty()) {
combainedBoolean.must(priceBooleanJunction.createQuery());
}
Query searchQuery = combainedBoolean.createQuery();
FullTextQuery query = fullTextEntityManager.createFullTextQuery(searchQuery, ServiceProvider.class);
LOGGER.info(query.toString());
最后一个日志打印 40、90 输入的以下内容
FullTextQueryImpl(+minPrice:[40 TO *] +maxPrice:[* TO 90])
数据库包含值 (min,max) 作为 (50, 80) 和 (80, 90)
结果还是空的。
【问题讨论】:
标签: hibernate-search hibernate-entitymanager