gpt4 book ai didi

java - 索引 neo4j 中的现有关系

转载 作者:行者123 更新时间:2023-12-01 14:08:45 27 4
gpt4 key购买 nike

是否可以在现有关系上添加索引。更具体地说,我有一个名为 Relatadness 的关系,其中有一个名为 Score(score 是 double)的属性,并且我想对其进行索引(使用 java 或通过 Web 客户端)。怎样才能做到这一点呢?提前致谢

最佳答案

由于您已经有了这些关系,因此您必须遍历所有这些关系。此代码示例将创建一个名为 RelatadnessIndex 的索引,并将索引中的关系存储在 score 键下:

    GlobalGraphOperations ggo = GlobalGraphOperations.at(db);
Index<Relationship> relatadnessIndex = db.index().forRelationships("RelatadnessIndex");
for (Relationship r : ggo.getAllRelationships()) {
if (r.getType().name().equals("Relatadness")) {
double score = (double) r.getProperty("score");
relatadnessIndex.add(r, "score", score);
}
}

请注意,默认情况下 Neo4j/Lucene 会将值索引为字符串,因此进行数字范围搜索将不起作用。如果您想将其存储为数字,则需要更改为添加如下:

relatadnessIndex.add(r, "score", new ValueContext( score ).indexNumeric() );

关于java - 索引 neo4j 中的现有关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18699089/

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