Gremlin 中的分页

Pagination in Gremlin

我正在尝试在 Gremlin 中进行分页。我已经按照 on gremlin recipes. 提供的解决方案进行操作,所以现在我正在使用 range() 步骤来截断结果。这很有效,因为当用户请求 x 个结果时,id 只查询其中的 x 个,而不执行速度明显更快的完整搜索。

但是在 Gremlin 文档中指出:

A Traversal’s result are never ordered unless explicitly by means of order()-step. Thus, never rely on the iteration order between TinkerPop3 releases and even within a release (as traversal optimizations may alter the flow).

顺序对于分页非常重要(我们不希望用户在不同页面上获得相同的结果)。

添加 order() 确实会减慢查询速度,因为它必须查询适用于搜索的所有顶点,然后用 range().

截断它

有什么想法可以解决这个问题以保持查询之间的一致性并且仍然有更短的非完整搜索查询时间?

文档是正确的,但可以使用一些额外的上下文。如果没有 order(),则无法保证特定顺序,除非底层图形数据库保证该顺序。 TinkerPop 应该保留该保证(如果存在)。所以,最终你需要考虑底层图会做什么。

当您使用 JanusGraph 时,我很确定它不能保证结果迭代的顺序,但有一些注意事项取决于您所做的索引类型。您可以阅读更多相关信息 here but may want to ask specific questions on the JanusGraph user list