一、属性、顶点、边操作
1、创建属性 PropertyKey
// 创建name属性,数据类型为 text,基数默认
graph.schema().propertyKey("name").asText().ifNotExist().create()
// 创建name属性,数据类型为 int,基数默认
graph.schema().propertyKey("age").asInt().ifNotExist().create()
// other,数据类型为text,基数为set
graph.schema().propertyKey("other").asText().valueSet().ifNotExist().create()
2、创建顶点
// 创建person顶点,属性为name,age,使用自定义数字id策略,name不能为空
graph.schema().vertexLabel("person").properties("name", "age").useCustomizeNumberId().nullableKeys("name").ifNotExist().create()
3、创建边
// 边关系为person到person的边,名称relation,边属性为relation
graph.schema().edgeLabel("relation").sourceLabel("person").targetLabel("person").properties("relation").ifNotExist().create()
4、添加数据
// T.label 为顶点名,T.id 为自定义主键数字 graph.addVertex(T.label, "person", T.id, 2001,"name", "巴达克", "age", 100) graph.addVertex(T.label, "person", T.id, 2002,"name", "孙悟空", "age", 40)
5、绑定关系
g.V(2001).addE('relation').to(g.V(2002)).property('relation','儿子')
g.V(2002).addE('relation').to(g.V(2002)).property('relation','父亲')
二、查询
1、日期类型查询
// 使用where查询日期
g.V().hasLabel('person').where( values('创建时间').is(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse('1990-07-01 00:00:00.000')))
// 使用filter查询日期
g.V().hasLabel('person').filter {it.get().value('创建时间') == new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse('1990-07-01 00:00:00.000')}
2、条件查询 多条件or和and组合查询
// 多条件or和and组合查询
g.V()
.hasLabel('古建筑', '企业', '人')
.or(
and(values('地理_经度').is(gt(116.38571098899912)), values('地理_经度').is(lt(116.42085172218476)), values('地理_纬度').is(gt(39.910126452476156)), values('地理_纬度').is(lt(39.937075910999745))),
and(values('经度').is(gt(116.38571098899912)), values('经度').is(lt(116.42085172218476)), values('纬度').is(gt(39.910126452476156)), values('纬度').is(lt(39.937075910999745)))
)
.where(
values('地址').is(eq('北京市'))
)
暑期编程PK赛
得CSDN机械键盘等精美礼品!


