大家好,我是洋仔,JanusGraph图解系列文章,`实时更新`~
源码分析相关可查看github(求star~~): https://github.com/YYDreamer/janusgraph
下述流程高清大图地址:https://www.processon.com/view/link/5f471b2e7d9c086b9903b629
版本:JanusGraph-0.5.2
转载文章请保留以下声明: >作者:洋仔聊编程 >微信公众号:匠心Java >原文地址:[https://liyangyang.blog.csdn.net/](https://liyangyang.blog.csdn.net/)
文章列出了JanusGraph在 全局图搜索和局部遍历 中支持的所有谓词。
下列比较谓词,枚举了用于索引查询并在上面的示例中使用:
String、numeric、Date和即时的数据类型可以支持所有谓词。
boolean和uuid仅支持neq和eq
Text枚举指定用于查询匹配文本或字符串值的搜索操作符。两种类型谓词区别:
有关全文和字符串搜索的更多信息,请参见第24.1节“全文搜索”。
下面列举了地理谓词:
有关地理搜索的详细信息,请参见第24.2节“地理映射”。 ### 23.4 查询示例
以下查询示例演示了教程上的一些谓词:
// 1)获取name属性为“hercules”的节点
g.V().has("name", "hercules")
// 2) Find all vertices with an age greater than 50
g.V().has("age", gt(50))
// or find all vertices between 1000 (inclusive) and 5000 (exclusive) years of age and order by increasing age
g.V().has("age", inside(1000, 5000)).order().by("age", incr)
// which returns the same result set as the following query but in reverse order
g.V().has("age", inside(1000, 5000)).order().by("age", decr)
// 3)获取所有给定经纬度50km内的所有place
g.E().has("place", geoWithin(Geoshape.circle(37.97, 23.72, 50)))
// 4) Find all edges where reason contains the word "loves"
// 4) 查找边reason属性中包含“loves”词的所有边
g.E().has("reason", textContains("loves"))
// or all edges which contain two words (need to chunk into individual words)
g.E().has("reason", textContains("loves")).has("reason", textContains("breezes"))
// or all edges which contain words that start with "lov"
g.E().has("reason", textContainsPrefix("lov"))
// or all edges which contain words that match the regular expression "br[ez]*s" in their entirety
g.E().has("reason", textContainsRegex("br[ez]*s"))
// or all edges which contain words similar to "love"
g.E().has("reason", textContainsFuzzy("love"))
// 5) Find all vertices older than a thousand years and named "saturn"
// 5)查询所有年龄大于1000年的并且姓名为“saturn”的节点
g.V().has("age", gt(1000)).has("name", "saturn")
虽然JanusGraph的复合索引(composite indexes)支持 可以存储在JanusGraph中的 任何数据类型, 但混合索引(mixed indexes )仅限于以下数据类型。
将来将支持其他数据类型。
Geoshape数据类型支持 :点,圆,框,线,多边形,多点,多线和多边形。
索引后端目前支持索引:点,圆,框,线,多边形,多点, 多线,多边形和几何集合。
仅通过混合索引支持地理空间索引查找。
要构建Geoshape,请使用以下方法:
//lat, lng
Geoshape.point(37.97, 23.72)
//lat, lng, radius in km
Geoshape.circle(37.97, 23.72, 50)
//SW lat, SW lng, NE lat, NE lng
Geoshape.box(37.97, 23.72, 38.97, 24.72)
//WKT
Geoshape.fromWkt("POLYGON ((35.4 48.9, 35.6 48.9, 35.6 49.1, 35.4 49.1, 35.4 48.9))")
//MultiPoint
Geoshape.geoshape(Geoshape.getShapeFactory().multiPoint().pointXY(60.0, 60.0).pointXY(120.0, 60.0)
.build())
//MultiLine
Geoshape.geoshape(Geoshape.getShapeFactory().multiLineString()
.add(Geoshape.getShapeFactory().lineString().pointXY(59.0, 60.0).pointXY(61.0, 60.0))
.add(Geoshape.getShapeFactory().lineString().pointXY(119.0, 60.0).pointXY(121.0, 60.0)).build())
//MultiPolygon
Geoshape.geoshape(Geoshape.getShapeFactory().multiPolygon()
.add(Geoshape.getShapeFactory().polygon().pointXY(59.0, 59.0).pointXY(61.0, 59.0)
.pointXY(61.0, 61.0).pointXY(59.0, 61.0).pointXY(59.0, 59.0))
.add(Geoshape.getShapeFactory().polygon().pointXY(119.0, 59.0).pointXY(121.0, 59.0)
.pointXY(121.0, 61.0).pointXY(119.0, 61.0).pointXY(119.0, 59.0)).build())
//GeometryCollection
Geoshape.geoshape(Geoshape.getGeometryCollectionBuilder()
.add(Geoshape.getShapeFactory().pointXY(60.0, 60.0))
.add(Geoshape.getShapeFactory().lineString().pointXY(119.0, 60.0).pointXY(121.0, 60.0).build())
.add(Geoshape.getShapeFactory().polygon().pointXY(119.0, 59.0).pointXY(121.0, 59.0)
.pointXY(121.0, 61.0).pointXY(119.0, 61.0).pointXY(119.0, 59.0)).build())
此外,通过GraphSON导入图形时,几何体可能由GeoJSON表示:
//string
"37.97, 23.72"
//list
[37.97, 23.72]
//GeoJSON feature
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
},
"properties": {
"name": "Dinagat Islands"
}
}
//GeoJSON geometry
{
"type": "Point",
"coordinates": [125.6, 10.1]
}
GeoJSON可以指定为Point,Circle,LineString或Polygon。多边形必须关闭。请注意, 与JanusGraph API不同,GeoJSON将坐标指定为lng lat。
如果您使用的是Elasticsearch,则可以对SET和LIST类型的属性进行索引。例如:
mgmt = graph.openManagement()
// 设置names属性为SET类型
nameProperty = mgmt.makePropertyKey("names").dataType(String.class).cardinality(Cardinality.SET).make()
mgmt.buildIndex("search", Vertex.class).addKey(nameProperty, Mapping.STRING.asParameter()).buildMixedIndex("search")
mgmt.commit()
// 插入一个节点
person = graph.addVertex()
person.property("names", "Robert")
person.property("names", "Bob")
graph.tx().commit()
// 现在查询它
g.V().has("names", "Bob").count().next() //1
g.V().has("names", "Robert").count().next() //1
如果转载此博文,请附上本文链接https://blog.csdn.net/csdn___lyy,谢谢合作~