Hibernate Search java spring,仅搜索具有指定ID的实体

当我想搜索具有特定 ID 的实体时遇到问题。我有我执行的 fullTextQuery,它工作正常,当我想说

仅在这些实体中搜索(提供的 ID 列表):

+(title:slovakia~2 leadText:slovakia~2 body:slovakia~2 software:slovakia~2) +verified:true +eid:(113 | 112 | 3)

http://img.mukewang.com/639adf7c000160f408640193.jpg

然后我得到 0 个结果,这些实体被索引并持久化,一切都应该正常工作,但它没有返回任何结果。

这是定义的实体属性:

@Id

@GeneratedValue

@Field(name = "eid")

@FieldBridge(impl = LongBridge.class)

private long id;

我试过,没有场桥,有 TermVector.YES 也没有任何额外的 @Field.. 注释。所有结果要么异常,要么就是没有结果。


搜索特定 ID 的正确方法是什么?


例如这里是工作查询:

http://img1.mukewang.com/639adf8b000115f710200233.jpg

查询的创建如下所示:

    return Optional.of(getQueryBuilder()
            .keyword()
            .onField("eid")
            .matching(stringBuilder.toString())
            .createQuery());


肥皂起泡泡
浏览 89回答 2
2回答

繁星点点滴滴

您尝试使用的语法(113 | 112 | 3)在此上下文中不正确。不解释查询的参数keyword,特别是不支持运算符。使用与任何提供的 ID 匹配的布尔连接:List<String> eids = ...;QueryBuilder qb = getQueryBuilder();BooleanJunction<?> idJunction = qb.bool();for (String eid : eids) {&nbsp; &nbsp; idJunction.should(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; qb.keyword()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .onField("eid")&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .matching(eid)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .createQuery()&nbsp; &nbsp; );}return idJunction.createQuery();请注意,如果您想添加其他查询,则不应使用相同的连接点。使用另一个连接idJunction.createQuery()作为其子句之一。

一只甜甜圈

从我对 hibernate-search 的一点经验来看,只有 Ranges 似乎适用于整数和长字段。在您此处的示例中,我希望以下查询可以正常工作:QueryBuilder qb = getQueryBuilder();BooleanJunction<?> idJunction = qb.bool();&nbsp;bool.must(NumericRangeQuery.newLongRange("eid", Long.valueOf(eid), Long.valueOf(eid), true, true).createQuery();Long.valueOf()在这种情况下,如果提供的值已经是 Long 值,则 Boxed是可选的。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java