Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan 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 the Neo4j® database connection neo4jconn. You can search a subgraph or the entire graph.

Examples

collapse all

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.

neo4jconn.Message
ans =

     []

The blank Message property indicates a successful connection.

Search the graph for all nodes that are labeled as 'Person' using the Neo4j® database connection neo4jconn.

nlabel = {'Person'};

graphinfo = searchGraph(neo4jconn,nlabel)
graphinfo = 

  struct with fields:

        Nodes: [7×3 table]
    Relations: [8×4 table]

graphinfo is a structure that contains the results of the search:

  • Nodes -- A table containing all starting and ending nodes that denote each matched relationship.

  • Relations -- A table containing all matched relationships.

Access the table of nodes.

graphinfo.Nodes
ans = 

         NodeLabels      NodeData                NodeObject          
         __________    ____________    ______________________________

    0    'Person'      [1×1 struct]    [1x1 database.neo4j.Neo4jNode]
    1    'Person'      [1×1 struct]    [1x1 database.neo4j.Neo4jNode]
    2    'Person'      [1×1 struct]    [1x1 database.neo4j.Neo4jNode]
    3    'Person'      [1×1 struct]    [1x1 database.neo4j.Neo4jNode]
    4    'Person'      [1×1 struct]    [1x1 database.neo4j.Neo4jNode]
    5    'Person'      [1×1 struct]    [1x1 database.neo4j.Neo4jNode]
    6    'Person'      [1×1 struct]    [1x1 database.neo4j.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 = 

         StartNodeID    RelationType    EndNodeID    RelationData
         ___________    ____________    _________    ____________

    1    0              'knows'         1            [1×1 struct]
    0    0              'knows'         2            [1×1 struct]
    3    1              'knows'         3            [1×1 struct]
    2    2              'knows'         1            [1×1 struct]
    5    3              'knows'         4            [1×1 struct]
    4    3              'knows'         5            [1×1 struct]
    6    5              'knows'         4            [1×1 struct]
    7    5              'knows'         6            [1×1 struct]

Access property keys for the first relationship.

graphinfo.Relations.RelationData{1}
ans = 

  struct with no fields.

The first relationship has no property keys.

Search the graph for all node labels in the database.

allnodes = nodeLabels(neo4jconn);

graphinfo = searchGraph(neo4jconn,allnodes);

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.

neo4jconn.Message
ans =

     []

The blank Message property indicates a successful connection.

Search the graph for the relationship type 'knows' using the Neo4j® database connection neo4jconn.

reltype = {'knows'};

graphinfo = searchGraph(neo4jconn,reltype)
graphinfo = 

  struct with fields:

        Nodes: [7×3 table]
    Relations: [8×4 table]

graphinfo is a structure that contains the results of the search:

  • Nodes -- A table containing all starting and ending nodes that denote each matched relationship.

  • Relations -- A table containing all matched relationships.

Access the table of nodes.

graphinfo.Nodes
ans = 

         NodeLabels      NodeData                NodeObject          
         __________    ____________    ______________________________

    0    'Person'      [1×1 struct]    [1x1 database.neo4j.Neo4jNode]
    2    'Person'      [1×1 struct]    [1x1 database.neo4j.Neo4jNode]
    1    'Person'      [1×1 struct]    [1x1 database.neo4j.Neo4jNode]
    3    'Person'      [1×1 struct]    [1x1 database.neo4j.Neo4jNode]
    5    'Person'      [1×1 struct]    [1x1 database.neo4j.Neo4jNode]
    4    'Person'      [1×1 struct]    [1x1 database.neo4j.Neo4jNode]
    6    'Person'      [1×1 struct]    [1x1 database.neo4j.Neo4jNode]

Access the table of relationships.

graphinfo.Relations
ans = 

         StartNodeID    RelationType    EndNodeID    RelationData
         ___________    ____________    _________    ____________

    0    0              'knows'         2            [1×1 struct]
    1    0              'knows'         1            [1×1 struct]
    2    2              'knows'         1            [1×1 struct]
    3    1              'knows'         3            [1×1 struct]
    4    3              'knows'         5            [1×1 struct]
    5    3              'knows'         4            [1×1 struct]
    6    5              'knows'         4            [1×1 struct]
    7    5              'knows'         6            [1×1 struct]

Search the graph for all relationship types in the database.

allreltypes = relationTypes(neo4jconn);

graphinfo = searchGraph(neo4jconn,allreltypes);

Input Arguments

collapse all

Neo4j database connection, specified as a Neo4jConnect object created using 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:

  • Row names in the table, which are Neo4j node identifiers of the matched database nodes.

  • The variable NodeLabels, which is a character vector that denotes the node label for each matched database node.

  • The variable NodeData, which is a structure array that contains node information such as property keys for each matched database node.

  • The variable NodeObject, which is the Neo4jNode object for each matched database node.

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:

  • Row names in the table, which are Neo4j relationship identifiers.

  • The variable StartNodeID, which is the node identifier for the start node for each matched relationship.

  • The variable RelationType, which is a character vector that denotes the relationship type for each matched relationship.

  • The variable EndNodeID, which is the node identifier for the end node for each matched relationship.

  • The variable RelationData, which is a structure array that contains property keys associated with each matched relationship.

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

Introduced in R2016b

Was this topic helpful?