-
Notifications
You must be signed in to change notification settings - Fork 5
Match
The Match-Statement is supported by establishing
a simple stack. Any vertex is able to initiate the match
-stack.
Vertex.match where: where-statement, as: return-value
=> returns a OrientSupport::MatchStatement Object
MatchStatement
Objects can connect edges ( via <<
), are able to compile
the stack and to execute
the query.
Edges are bind to the stack via
Edge.connect where: , while:, max_depth:, as:
Subsequent Vertex.match
-statements can be assigned via <<
, too.
Lets start with a simple graph:
10 V2
-vertices, with an attribute node: 1 .. 10 connected via E2
-Edges to a V1
-Vertex with an attribute item: 1
V.create_class :v1
V1.create_class :v2
E.create_class :e1
E1.create_class :e2
E2.create_class :e3
vertices = (1..10).map{|y| V2.create node: y}
E2.create from: V1.create( item: 1 ), to: vertices
#INFO->CREATE VERTEX v1 set item = 1
#INFO->CREATE EDGE e2 from #74:0 to [#82:0, #83:0, #84:0, #85:0, #86:0, #87:0, #88:0, #89:0, #82:1, #83:1]
A Match-Query starts at a given Vertex-Class. The where-cause narrows the sample to certain records. In its simplest version this is returned:
> V2.match( where:{node: 8} ).compile
=> "match {class: v2, as: v2s, where: ( node = 8)} return v2s"
>V2.match( where:{node: 8} ).execute(as: :flatten).to_human
=> ["<V2[89:0]: in: {E2=>1}, node : 8>"]
ét voila: The V2-record with attribute node: 8
Lets inspect the next layer.
The adjacent node is connected via :in
. So
> v = V2.match( where:{ node: 8}) << E1.connect(:in, as: :b)
> v.compile(as: flatten).to_human
#INFO->match {class: v2, as: v2s, where: ( node = 8)}.in(e1){as: b} return v2s, b
=> ["<V2[89:0]: in: {E2=>1}, node : 8>", "<V1[74:0]: out: {E2=>10}, item : 1>"]
We get a table with two columns, displaying the start vertex and the connected one (containing 10 E2
-Edges).
To inspect the next layer, we have to follow the :out
-path. This is released by adding another connect
to the query
> v= V2.match( where:{ node: 8}, as: nil) <<
E2.connect(:in, as: :b) <<
E2.connect(:out, as: :c)
> v.compile(as: :array).to_human
INFO->match {class: v2, where: ( node = 8)}.in(e2){as: b}.out(e2){as: c} return b, c
=> [["<V1[74:0]: out: {E2=>10}, item : 1>", "<V2[82:0]: in: {E2=>1}, node : 1>"],
["<V1[74:0]: out: {E2=>10}, item : 1>", "<V2[83:0]: in: {E2=>1}, node : 2>"],
["<V1[74:0]: out: {E2=>10}, item : 1>", "<V2[84:0]: in: {E2=>1}, node : 3>"],
["<V1[74:0]: out: {E2=>10}, item : 1>", "<V2[85:0]: in: {E2=>1}, node : 4>"],
["<V1[74:0]: out: {E2=>10}, item : 1>", "<V2[86:0]: in: {E2=>1}, node : 5>"],
["<V1[74:0]: out: {E2=>10}, item : 1>", "<V2[87:0]: in: {E2=>1}, node : 6>"],
["<V1[74:0]: out: {E2=>10}, item : 1>", "<V2[88:0]: in: {E2=>1}, node : 7>"],
["<V1[74:0]: out: {E2=>10}, item : 1>", "<V2[89:0]: in: {E2=>1}, node : 8>"],
["<V1[74:0]: out: {E2=>10}, item : 1>", "<V2[82:1]: in: {E2=>1}, node : 9>"],
["<V1[74:0]: out: {E2=>10}, item : 1>", "<V2[83:1]: in: {E2=>1}, node : 10>"]]
Overview
Data Management
- Joining Tables, embedded Lists
- Links and Link Lists
- Relations
- Bidirectional Connections
- Working with Hashes
Public API
- Database
- Model CRUD
Misc