自定义存储库的Spring Data Solr优先级 [英] Spring Data Solr Precedence for Custom Repository

查看:67
本文介绍了自定义存储库的Spring Data Solr优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Spring Data Solr自定义存储库中实现以下内容:

I need to implement the following in a Spring Data Solr custom repository:

(X或Y)和Z

(X OR Y) AND Z

我当前的代码如下:

Criteria criteria = new Criteria("x").is(X_VALUE);
criteria = criteria.or(new Criteria("y").is(Y_VALUE);
criteria = criteria.and(new Criteria("z").is(Z_VALUE);

但是运行此代码,我得到以下优先级:

But running this code I get the following precedence:

X OR(Y和Z)

X OR (Y AND Z)

有什么想法吗?

推荐答案

当前的API不允许这种条件组合. DATASOLR-105 上有一个补丁,尽管它不能完全解决问题,但可能会有所帮助

The current API does not allow this combination of criteria. There's a patch attached to DATASOLR-105 which could help though it does not solve the problem fully.

使用SimpleStringCriteria可能现在有所帮助.请注意,必须将值转换为Solr可读格式.

Usage of SimpleStringCriteria might help for now. Please be aware of the fact, that values have to be converted to a Solr readable format.

new SimpleQuery(new SimpleStringCriteria("(x or y) and z"));

更新

版本1.2将解决此问题,因此可以按如下方式创建查询.

Version 1.2 will have this issue fixed, so that its possible to create the query as follows.

Criteria orPart = Criteria.where("x").is("foo").or("y").is("bar");
Criteria andPart = Criteria.where("z").is("roo");
Query query = new SimpleQuery(orPart.and(andPart));

这篇关于自定义存储库的Spring Data Solr优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆