如何使用graph.getVertices()
获取特定顶点。
我的班级名称Station
已扩展为V(顶点)。
类别' (数据类型为LINK)是Station
类别可以是'#12:13'或者'#12:14'或者'#12:15'
我想使用graph.getVertices()
JAVA
来获取具体的category
。
类似的东西:
graph.getVertices("Station category = '#12:13'");
graph.getVertices("Excluded Station Category = '#12:13'");
有什么建议吗?
答案 0 :(得分:1)
我使用这个简单的结构来尝试你的案例(category
的类型为LINK
):
<强>类强>:
我使用此代码检索了您要查找的结果:
JAVA代码:
package yourPackage;
import java.io.IOException;
import com.orientechnologies.orient.client.remote.OServerAdmin;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
public class YourClass{
private static String remote = "remote:localhost/";
public static void main(String[] args) {
String DBname = "yourDBname";
String currentPath = remote + DBname;
OServerAdmin serverAdmin;
try {
serverAdmin = new OServerAdmin(currentPath).connect("root", "root");
if (serverAdmin.existsDatabase()) {
OrientGraph g = new OrientGraph(currentPath);
String yourRid = "#13:0";
Iterable<Vertex> targets = g.getVerticesOfClass("Station");
System.out.println("Category @rid = " + yourRid);
System.out.println();
for (Vertex target : targets) {
Vertex category = target.getProperty("category");
if (category.getId().toString().equals(yourRid)) {
System.out.println("Matched Station: " + target.getProperty("name") + " Category: "
+ category.getProperty("name") + " (" + category.getId() + ")");
System.out.println();
} else {
System.out.println("Excluded Station: " + target.getProperty("name") + " Category: "
+ category.getProperty("name") + " (" + category.getId() + ")");
}
}
}
else {
System.out.println("Database " + DBname + " not found");
}
serverAdmin.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
<强>输出强>:
Category @rid = #13:0
Matched Station: First Category: category 1 (#13:0)
Excluded Station: Second Category: category 2 (#13:1)
Excluded Station: Third Category: category 3 (#13:2)
希望有所帮助
答案 1 :(得分:0)
获取Station类的所有顶点,尝试:
g.V('_class','Station')
或按类别字段过滤
g.V('_class','Station').has('category','catvalue 123')
或者如果你有多个匹配:
g.V('_class', 'Station').has('category', T.in,['12:13','12:14'])
或特定ID
g.v('12:13')
查找2个顶点之间是否存在边,可以使用:
g.v(stationVtxId).outE('edge_label').sideEffect{x=it}.inV.filter{it == g.v(catVtxId)}.back(2)
答案 2 :(得分:0)
我在类Station
的属性类别中使用了索引create class Station extends V
create class Category extends V
create property Station.name STRING
create property Station.category LINK Category
create property Category.name STRING
create index Station.category ON Station (category) NOTUNIQUE
insert into category(name) values ("category A") // 13:0
insert into category(name) values ("category B") // 13:1
insert into Station(name,category) values ("Station 1",#13:0)
insert into Station(name,category) values ("Station 2",#13:1)
JAVA