searchGraph
Search for subgraph or entire graph in Neo4j database
Syntax
Description
Examples
Search for graph information in a Neo4j® database by using node labels and display the information.
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 =
[]
Search the graph for all nodes with the label 'Person' using the Neo4j database connection.
nlabel = {'Person'};
graphinfo = searchGraph(neo4jconn,nlabel)graphinfo = struct with fields:
Nodes: [7×3 table]
Relations: [8×5 table]
graphinfo is a structure that contains the results of the search:
All start and end nodes that denote each matched relationship
All matched relationships
Access the table of nodes.
graphinfo.Nodes
ans=7×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]
4 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
5 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
9 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
Access property keys for the first node.
graphinfo.Nodes.NodeData{1}ans = struct with fields:
name: 'User1'
Access the table of relationships.
graphinfo.Relations
ans=8×5 table
StartNodeID RelationType EndNodeID RelationData RelationObject
___________ ____________ _________ ____________ _______________________________________
1 0 'knows' 1 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
0 0 'knows' 2 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
3 1 'knows' 3 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
2 2 'knows' 1 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
5 3 'knows' 4 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
4 3 'knows' 5 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
6 5 'knows' 4 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
8 5 'knows' 9 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
Access property keys for the first relationship. The first relationship has no property keys.
graphinfo.Relations.RelationData{1}ans = struct with no fields.
Search the graph for all node labels in the database.
allnodes = nodeLabels(neo4jconn); graphinfo = searchGraph(neo4jconn,allnodes);
Close the database connection.
close(neo4jconn)
Search for graph information in a Neo4j® database by using the relationship type and display the information.
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 =
[]
Search the graph for the relationship type 'knows' using the Neo4j database connection.
reltype = {'knows'};
graphinfo = searchGraph(neo4jconn,reltype)graphinfo = struct with fields:
Nodes: [7×3 table]
Relations: [8×5 table]
graphinfo is a structure that contains the results of the search:
All start and end nodes that denote each matched relationship
All matched relationships
Access the table of nodes.
graphinfo.Nodes
ans=7×3 table
NodeLabels NodeData NodeObject
__________ ____________ ___________________________________
0 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
2 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
1 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
3 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
5 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
4 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
9 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
Access the table of relationships.
graphinfo.Relations
ans=8×5 table
StartNodeID RelationType EndNodeID RelationData RelationObject
___________ ____________ _________ ____________ _______________________________________
0 0 'knows' 2 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
1 0 'knows' 1 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
2 2 'knows' 1 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
3 1 'knows' 3 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
4 3 'knows' 5 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
5 3 'knows' 4 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
6 5 'knows' 4 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
8 5 'knows' 9 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
Search the graph for all relationship types in the database.
allreltypes = relationTypes(neo4jconn); graphinfo = searchGraph(neo4jconn,allreltypes);
Close the database connection.
close(neo4jconn)
Search for graph information in a Neo4j® database by using node labels. 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 =
[]
Search the graph for all nodes with the node label Person using the Neo4j database connection. Return graph information as a directed graph by using the 'DataReturnFormat' name-value pair argument with the value 'digraph'.
nlabel = "Person"; graphinfo = searchGraph(neo4jconn,nlabel, ... 'DataReturnFormat','digraph');
Display the edges of the directed graph.
graphinfo.Edges
ans=8×3 table
EndNodes RelationType RelationData
______________ ____________ ____________
{'0'} {'1'} {'knows'} {1×1 struct}
{'0'} {'2'} {'knows'} {1×1 struct}
{'1'} {'3'} {'knows'} {1×1 struct}
{'2'} {'1'} {'knows'} {1×1 struct}
{'3'} {'4'} {'knows'} {1×1 struct}
{'3'} {'5'} {'knows'} {1×1 struct}
{'5'} {'4'} {'knows'} {1×1 struct}
{'5'} {'9'} {'knows'} {1×1 struct}
Display the nodes of the directed graph.
graphinfo.Nodes
ans=7×3 table
Name NodeLabels NodeData
_____ __________ ____________
{'0'} {'Person'} {1×1 struct}
{'1'} {'Person'} {1×1 struct}
{'2'} {'Person'} {1×1 struct}
{'3'} {'Person'} {1×1 struct}
{'4'} {'Person'} {1×1 struct}
{'5'} {'Person'} {1×1 struct}
{'9'} {'Person'} {1×1 struct}
Close the database connection.
close(neo4jconn)
Input Arguments
Neo4j database connection, specified as a Neo4jConnect object created with the function neo4j.
Search criteria, specified as a cell array of character vectors or string array. To search by nodes, specify one or more node labels as character vectors in the cell array. To search by relationships, specify one or more relationship types as character vectors in the cell array. Or, specify a string array for multiple node labels or relationship types.
Data Types: cell | string
Output Arguments
Graph information in the Neo4j database that matches the search criteria, returned as a structure with these fields.
| Field | Description |
|---|---|
| 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. If |
| Table that contains relationship information for
the nodes in the
The row names in the table are Neo4j relationship identifiers. If
|
Note
When you use the 'DataReturnFormat' name-value
pair argument with the value 'digraph', the
searchGraph function returns graph 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 graphinfo output argument.
Version History
Introduced in R2016b
See Also
neo4j | searchNode | searchNodeByID | searchRelation | relationTypes | nodeLabels | close
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.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- 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)