前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【翻译】图解Janusgraph系列-查询谓词和数据类型(Janusgraph Search Predicates and Data Types)

【翻译】图解Janusgraph系列-查询谓词和数据类型(Janusgraph Search Predicates and Data Types)

作者头像
洋仔聊编程
发布2022-05-11 10:03:50
6330
发布2022-05-11 10:03:50
举报

图解Janusgraph系列-查询谓词和数据类型(janusgraph Search predicates and data types)

大家好,我是洋仔,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在 全局图搜索和局部遍历 中支持的所有谓词。

1 比较谓词

下列比较谓词,枚举了用于索引查询并在上面的示例中使用:

  • eq (equal)  
  • neq (not equal)   
  • gt (greater than)   
  • gte (greater than or equal)   
  • lt (less than)  
  • lte (less than or equal)

String、numeric、Date和即时的数据类型可以支持所有谓词。 

boolean和uuid仅支持neq和eq

2 文本谓词

Text枚举指定用于查询匹配文本或字符串值的搜索操作符。两种类型谓词区别:

  • 文本搜索谓词在文本字符串被标记化后与文本字符串中的单个单词匹配。这些谓词不区分大小写。
  • textContains:如果(至少)文本字符串中的一个单词与查询字符串匹配,则为true
  • textContainsPrefix:如果(至少)文本字符串中的一个单词以查询字符串开头,则为true
  • textContainsRegex:如果(至少)文本字符串中的一个单词与给定的正则表达式匹配,则为true
  • textContainsFuzzy:如果(至少)文本字符串中的一个单词与查询字符串相似(基于Levenshtein编辑距离),则为true
  • 字符串搜索谓词与整个字符串值匹配
  • textPrefix:如果字符串值以给定的查询字符串开头
  • textRegex:如果字符串值与给定的正则表达式完全匹配
  • textFuzzy:如果字符串值类似于给定的查询字符串(基于Levenshtein编辑距离)

有关全文和字符串搜索的更多信息,请参见第24.1节“全文搜索”。

3 地理谓词

下面列举了地理谓词: 

  • geoIntersect  如果两个几何对象具有至少一个共同点(相反geoDisjoint),则这是正确的。 
  • geoWithin  如果一个几何对象包含另一个几何对象,则成立 
  • geoDisjoint  如果两个几何对象没有共同的点(相反geoIntersect),则这是正确的。 
  • geoContains  如果一个几何对象被另一个包含,则该方法成立。

有关地理搜索的详细信息,请参见第24.2节“地理映射”。 ### 23.4 查询示例

4 查询示例

以下查询示例演示了教程上的一些谓词:

代码语言:javascript
复制
// 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")

5 支持数据类型

虽然JanusGraph的复合索引(composite indexes)支持 可以存储在JanusGraph中的 任何数据类型, 但混合索引(mixed indexes )仅限于以下数据类型。

  • Byte
  • Short
  • Integer
  • Long
  • Float
  • Double
  • String
  • Geoshape
  • Date
  • Instant
  • UUID

将来将支持其他数据类型。

6 地理位置数据类型

Geoshape数据类型支持 :点,圆,框,线,多边形,多点,多线和多边形。

索引后端目前支持索引:点,圆,框,线,多边形,多点, 多线,多边形和几何集合。

仅通过混合索引支持地理空间索引查找。

要构建Geoshape,请使用以下方法:

代码语言:javascript
复制
//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表示:

代码语言:javascript
复制
//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。

7 集合

如果您使用的是Elasticsearch,则可以对SET和LIST类型的属性进行索引。例如:

代码语言:javascript
复制
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,谢谢合作~

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2022-04-30,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 图解Janusgraph系列-查询谓词和数据类型(janusgraph Search predicates and data types)
    • 图数据库文章总目录:
      • 1 比较谓词
        • 2 文本谓词
          • 3 地理谓词
            • 4 查询示例
              • 5 支持数据类型
                • 6 地理位置数据类型
                  • 7 集合
                  相关产品与服务
                  图数据库 KonisGraph
                  图数据库 KonisGraph(TencentDB for KonisGraph)是一种云端图数据库服务,基于腾讯在海量图数据上的实践经验,提供一站式海量图数据存储、管理、实时查询、计算、可视化分析能力;KonisGraph 支持属性图模型和 TinkerPop Gremlin 查询语言,能够帮助用户快速完成对图数据的建模、查询和可视化分析。
                  领券
                  问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档