Ravendb 按值查询顺序
Ravendb query order by value
我有字段为 score
和 id
的对象。我需要从 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
条件,以 filter 为这些 id大于“7”
所以查询应该是这样的:
final List<SomeClass> players = session.query(SomeClass.class, SomeIndexClass.class)
.whereGreaterThan("id", 7)
.orderByDescending("score", OrderingType.LONG)
.skip(from)
.take(count)
.toList();
查看文档 link:
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 代码 。
我有字段为 score
和 id
的对象。我需要从 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
条件,以 filter 为这些 id大于“7”
所以查询应该是这样的:
final List<SomeClass> players = session.query(SomeClass.class, SomeIndexClass.class)
.whereGreaterThan("id", 7)
.orderByDescending("score", OrderingType.LONG)
.skip(from)
.take(count)
.toList();
查看文档 link:
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 代码 。