如何从 OCompositeKey 中省略密钥?

How to omit key from an OCompositeKey?

我为属性创建了一个边缘索引(输出:Link,输入:Link,类型:字符串)

我想在不指定 type 属性 的情况下通过以下方式查询索引:

Iterable<Edge> edges = noTrx.getEdges("e." + label, new OCompositeKey(vertexA.getId(), vertexB.getId()));

不幸的是,如果我从 OCompositeKey 中省略类型,则无法找到任何元素。

有没有办法查询索引并省略type?或者我是否需要创建一个只包含 out 和 in 的专用索引?

完整示例来源:

https://github.com/Jotschi/orientdb-playground/blob/e5bb027df171a04bc87d3b108ee58cc86499b7c3/src/test/java/de/jotschi/orientdb/EdgeIndexTest.java

你的classHAS_ITEM有两个索引

如果您还想查找类型,则必须使用索引 e.has_item_type

Iterable<Edge> edges = noTrx.getEdges("e." + label +"_type", new OCompositeKey(root.getId(), foundElement.getId(),type));

否则你可以使用索引 e.has_item

Iterable<Edge> edges = noTrx.getEdges("e." + label, new OCompositeKey(root.getId(), foundElement.getId()));

希望对您有所帮助。

您使用哈希索引,所以提供的方法是正确的。但是,如果您将使用基于树的索引并使用嵌入式数据库,则可以使用没有类型但有点棘手的复合键。您应该调用

而不是调用 getEdges 函数

index.iterateEntriesMajor(new OCompositeKey(root.getId(), foundElement.getId()))

然后对结果中的每条记录调用graph.getEdge(record)

我注意到你使用了 noTX 图形实现,我不建议在生产中使用 noTx 实现,它可能会导致数据不一致和损坏的图形状态。