This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

searchGraph

Search for subgraph or entire graph in Neo4j database

Syntax

graphinfo = searchGraph(neo4jconn,criteria)

Description

example

graphinfo = searchGraph(neo4jconn,criteria) returns graph information based on the search criteria using a Neo4j® database connection. You can search for a subgraph or the entire graph.

Examples

collapse all

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)

Input Arguments

collapse all

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

collapse all

Graph information in the Neo4j database that matches the search criteria, returned as a structure with these fields.

FieldDescription

Nodes

Table that contains node information for each node in the Relations table. The Nodes table contains these variables:

  • NodeLabels — Character vector that denotes the node label for each matched database node

  • NodeData — Structure array that contains node information such as property keys for each matched database node

  • NodeObjectNeo4jNode object for each matched database node

The row names in the table are Neo4j node identifiers of the matched database nodes.

If criteria contains node labels, the output is automatically sorted by StartNodeID and Label.

Relations

Table that contains relationship information for the nodes in the Nodes table. The Relations table contains these variables:

  • StartNodeID — Node identifier for the start node for each matched relationship

  • RelationType — Character vector that denotes the relationship type for each matched relationship

  • EndNodeID — Node identifier for the end node for each matched relationship

  • RelationData — Structure array that contains property keys associated with each matched relationship

  • RelationObjectNeo4jRelation object that represents each matched relationship

The row names in the table are Neo4j relationship identifiers.

If criteria contains relationship types, the output is automatically sorted by RelationID.

Introduced in R2016b