java - Ravendb 按值查询顺序
问题描述
我有带有字段的对象score
和id
. from
我需要从to中获取一些此类对象from + count
,这些对象按字段score
降序排列。id
在每个等于范围内,如果存在,我需要获取该范围顶部具有特定值的对象。
例子:
1. score = 10, id = 5
2. score = 20, id = 6
3. score = 20, id = 7
4. score = 20, id = 8
5. score = 30, id = 9
具体值id
= 7, from
= 0, count
= 2
预期结果:
1. score = 30, id = 9
2. score = 20, id = 7 <--- my specific value on top of equal range, where score = 20
我写了简单的查询:
final List<SomeClass> players = session.query(SomeClass.class, SomeIndexClass.class)
.orderByDescending("score", OrderingType.LONG)
.skip(from)
.take(count)
.toList();
但这并没有考虑到具有特定价值的条件id
。我该怎么做?
解决方案
如果您的索引中有此id
字段的索引,那么您可以whereGreaterThan
在查询中添加一个条件,以过滤那些大于“7”的 id
所以查询会是这样的:
final List<SomeClass> players = session.query(SomeClass.class, SomeIndexClass.class)
.whereGreaterThan("id", 7)
.orderByDescending("score", OrderingType.LONG)
.skip(from)
.take(count)
.toList();
请参阅文档链接:
https ://ravendb.net/docs/article-page/5.1/java/indexes/querying/filtering#where---numeric-property
是id
文件编号吗?因为那时它不必被索引,应该只在查询中添加“where”条件即可工作。参见:https ://ravendb.net/docs/article-page/5.1/java/indexes/querying/basics#example-ii---filtering
顺便说一句,查看https://demo.ravendb.net/中的代码示例在
每个示例中,单击“Java”选项卡以查看示例 Java 代码。
推荐阅读
- excel - 如何访问嵌套字典的键?
- python - Apache Beam 数据流管道 (python) 中步骤的 If 语句
- javascript - 从 Firefox 开发者工具强制全屏
- docker - Kubectl 设置图像并以“rpc 错误:代码 = 4 desc = 超出上下文期限”结尾
- c# - 读取文件内存太大
- flutter - 如何防止页面被弹出?
- php - set_exception_handler() 期望参数 (exception_handler) 是一个有效的回调
- sql - 为什么不建议将产品规格存储在单列中?
- nativescript - Nativescript 6.1.1 应用程序在 --release 模式下崩溃,在调试中工作
- r - R非标准评估:将变量的名称作为参数传递给函数并让函数为其赋值