searchRelation
Search relationships for Neo4j database node
Syntax
Description
returns relationship information for the origin node relinfo
= searchRelation(neo4jconn
,nodeinfo
,direction
)nodeinfo
and
relationship direction using a Neo4j® database connection. The search starts from the origin node. To find
an origin node, use searchNode
or searchNodeByID
.
Examples
Search for Incoming Relationship
Search for information about a relationship in a Neo4j® database and display the information.
Assume that you have graph data stored in a Neo4j database that represents a social neighborhood. This database has seven nodes and eight relationships. Each node has only one unique property key name
with a value ranging from User1
through User7
. Each relationship has the type knows
.
Create a Neo4j database connection using the URL http://localhost:7474/db/data
, user name neo4j
, and password matlab
.
url = 'http://localhost:7474/db/data'; username = 'neo4j'; password = 'matlab'; neo4jconn = neo4j(url,username,password);
Check the Message
property of the Neo4j connection object neo4jconn
. The blank Message
property indicates a successful connection.
neo4jconn.Message
ans = []
Retrieve the origin node nodeinfo
using the Neo4j database connection and the node identifier 3
.
nodeid = 3; nodeinfo = searchNodeByID(neo4jconn,nodeid);
Search for incoming relationships using the Neo4j database connection and the origin node nodeinfo
.
direction = 'in';
relinfo = searchRelation(neo4jconn,nodeinfo,direction)
relinfo = struct with fields:
Origin: 3
Nodes: [2×3 table]
Relations: [1×5 table]
relinfo
is a structure that contains the results of the search:
Origin
— The node identifier for the specified origin nodeNodes
— A table containing all start and end nodes for each matched relationshipRelations
— A table containing all matched relationships
Access the table of nodes.
relinfo.Nodes
ans=2×3 table
NodeLabels NodeData NodeObject
__________ ____________ ___________________________________
1 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
3 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
Access the table of relationships.
relinfo.Relations
ans=1×5 table
StartNodeID RelationType EndNodeID RelationData RelationObject
___________ ____________ _________ ____________ _______________________________________
3 1 'knows' 3 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
Close the database connection.
close(neo4jconn)
Search Relationships by Type and Distance
Search for information about relationships in a Neo4j® database and display the information. Specify the relationship type and distance to search.
Assume that you have graph data stored in a Neo4j database that represents a social neighborhood. This database has seven nodes and eight relationships. Each node has only one unique property key name
with a value ranging from User1
through User7
. Each relationship has the type knows
.
Create a Neo4j database connection using the URL http://localhost:7474/db/data
, user name neo4j
, and password matlab
.
url = 'http://localhost:7474/db/data'; username = 'neo4j'; password = 'matlab'; neo4jconn = neo4j(url,username,password);
Check the Message
property of the Neo4j connection object neo4jconn
. The blank Message
property indicates a successful connection.
neo4jconn.Message
ans = []
Retrieve the origin node nodeinfo
using the Neo4j database connection and the node identifier 3
.
nodeid = 3; nodeinfo = searchNodeByID(neo4jconn,nodeid);
Search for incoming relationships using the Neo4j database connection and the origin node nodeinfo
. Refine the search by filtering for the relationship type knows
and for nodes at a distance of two or fewer.
direction = 'in'; reltypes = {'knows'}; relinfo = searchRelation(neo4jconn,nodeinfo,direction, ... 'RelationTypes',reltypes,'Distance',2)
relinfo = struct with fields:
Origin: 3
Nodes: [4×3 table]
Relations: [3×5 table]
relinfo
is a structure that contains the results of the search:
Origin
— The node identifier for the specified origin nodeNodes
— A table containing all start and end nodes for each matched relationshipRelations
— A table containing all matched relationships
Access the table of nodes.
relinfo.Nodes
ans=4×3 table
NodeLabels NodeData NodeObject
__________ ____________ ___________________________________
0 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
1 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
2 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
3 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
Access the table of relationships.
relinfo.Relations
ans=3×5 table
StartNodeID RelationType EndNodeID RelationData RelationObject
___________ ____________ _________ ____________ _______________________________________
3 1 'knows' 3 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
2 2 'knows' 1 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
1 0 'knows' 1 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
Close the database connection.
close(neo4jconn)
Return Relationship Information as Directed Graph
Search for information about outgoing relationships in a Neo4j® database. Return the information as a directed graph and display the edges and nodes of the graph.
Assume that you have graph data stored in a Neo4j database that represents a social neighborhood. This database has seven nodes and eight relationships. Each node has only one unique property key name
with a value ranging from User1
through User7
. Each relationship has the type knows
.
Create a Neo4j database connection using the URL http://localhost:7474/db/data
, user name neo4j
, and password matlab
.
url = 'http://localhost:7474/db/data'; username = 'neo4j'; password = 'matlab'; neo4jconn = neo4j(url,username,password);
Check the Message
property of the Neo4j connection object neo4jconn
. The blank Message
property indicates a successful connection.
neo4jconn.Message
ans = []
Retrieve the origin node nodeinfo
using the Neo4j database connection and the node identifier 3
.
nodeid = 3; nodeinfo = searchNodeByID(neo4jconn,nodeid);
Search for outgoing relationships using the Neo4j database connection and the origin node nodeinfo
. Return relationship information as a directed graph by using the 'DataReturnFormat'
name-value pair argument with the value 'digraph'
.
direction = 'out'; relinfo = searchRelation(neo4jconn,nodeinfo,direction, ... 'DataReturnFormat','digraph')
relinfo = digraph with properties: Edges: [2×3 table] Nodes: [3×3 table]
Display the edges of the directed graph.
relinfo.Edges
ans=2×3 table
EndNodes RelationType RelationData
______________ ____________ ____________
{'3'} {'4'} {'knows'} {1×1 struct}
{'3'} {'5'} {'knows'} {1×1 struct}
Display the nodes of the directed graph.
relinfo.Nodes
ans=3×3 table
Name NodeLabels NodeData
_____ __________ ____________
{'3'} {'Person'} {1×1 struct}
{'4'} {'Person'} {1×1 struct}
{'5'} {'Person'} {1×1 struct}
Close the database connection.
close(neo4jconn)
Input Arguments
neo4jconn
— Neo4j database connection
Neo4jConnect
object
Neo4j database connection, specified as a Neo4jConnect
object created with the function neo4j
.
nodeinfo
— Origin node information
Neo4jNode
object | numeric scalar
Origin node information, specified as a Neo4jNode
object or numeric scalar that denotes a node
identifier.
Data Types: double
direction
— Relationship direction
'in'
| 'out'
Relationship direction, specified as either 'in'
for an incoming
relationship or 'out'
for an outgoing relationship. The relationships
are associated with the specified origin node.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: relinfo =
searchRelation(neo4jconn,nodeinfo,'in','RelationTypes',{'knows'},'Distance',2)
returns the relationship information for the incoming relationships, which have the
relationship type knows
and are two or fewer nodes away from the
origin node.
RelationTypes
— Relationship types
character vector | string scalar | cell array of character vectors | string array
Relationship types, specified as a comma-separated pair consisting of
'RelationTypes'
and a character vector, string
scalar, cell array of character vectors, or string array. To search for
relationships using only one relationship type, use a character vector
or string scalar. To search for relationships using numerous
relationship types, use a cell array of character vectors or string
array.
Example: 'RelationTypes',{'knows'}
Data Types: char
| cell
| string
Distance
— Node distance
numeric scalar
Node distance, specified as a comma-separated pair consisting of
'Distance'
and a positive numeric scalar. For
example, if the node distance is three,
searchRelation
returns information for nodes
that are three or fewer nodes away from the origin node
nodeinfo
.
Example: 'Distance',3
Data Types: double
DataReturnFormat
— Data return format
'struct'
(default) | 'digraph'
Data return format, specified as the comma-separated pair consisting
of 'DataReturnFormat'
and the value
'struct'
for a structure or
'digraph'
for a digraph
object. Specify
this argument to return relationship information as a
digraph
object.
Output Arguments
relinfo
— Relationship information
structure
Relationship information in the Neo4j database that matches the search criteria from the origin node
nodeinfo
, returned as a structure with these
fields.
Field | Description |
---|---|
| Node identifier of the origin node
|
| Table that contains node information for each node
in the
The row names in the table are Neo4j node identifiers of the matched database nodes. |
| Table that contains relationship information for
the nodes in the
The row names in the table are Neo4j relationship identifiers. |
Note
When you use the 'DataReturnFormat'
name-value
pair argument with the value 'digraph'
, the
searchRelation
function returns relationship
information in a digraph
object. The resulting
digraph
object contains the same data as the
digraph
object created when you execute the
neo4jStruct2Digraph
function using the relinfo
output argument.
Version History
Introduced in R2016b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)