gpt4 book ai didi

java - Ravendb 按值查询顺序

转载 作者:行者123 更新时间:2023-12-03 23:02:04 25 4
gpt4 key购买 nike

我有带字段的对象 scoreid .我需要从 from 获取一些此类对象至 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文档 ID ?
因为那么它不必被索引,应该可以工作,只需将“where”条件添加到查询中。
见: https://ravendb.net/docs/article-page/5.1/java/indexes/querying/basics#example-ii---filtering
顺便说一句,查看 代码示例 https://demo.ravendb.net/
在每个示例中,单击“Java”选项卡以查看 示例 Java 代码 .

关于java - Ravendb 按值查询顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65015866/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com