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.

searchRelation

Search relationships for Neo4j database node

Syntax

relinfo = searchRelation(neo4jconn,nodeinfo,direction)
relinfo = searchRelation(neo4jconn,nodeinfo,direction,Name,Value)

Description

example

relinfo = searchRelation(neo4jconn,nodeinfo,direction) returns relationship information for the origin node nodeinfo and relationship direction using the Neo4j® database connection neo4jconn. The search starts from the origin node. To find an origin node, use searchNode or searchNodeByID.

example

relinfo = searchRelation(neo4jconn,nodeinfo,direction,Name,Value) returns relationship information with additional options specified by one or more Name,Value pair arguments.

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.

Retrieve the origin node nodeinfo using the Neo4j® database connection neo4jconn and node identifier nodeid.

nodeid = 3;

nodeinfo = searchNodeByID(neo4jconn,nodeid);

Search for incoming relationships using the Neo4j® database connection neo4jconn and origin node nodeinfo.

direction = 'in';

relinfo = searchRelation(neo4jconn,nodeinfo,direction)
relinfo = 

  struct with fields:

       Origin: 3
        Nodes: [2×3 table]
    Relations: [1×4 table]

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

  • Origin -- The node identifier for the specified origin node.

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

  • Relations -- A table containing all matched relationships.

Access the table of nodes.

relinfo.Nodes
ans = 

         NodeLabels      NodeData                NodeObject          
         __________    ____________    ______________________________

    1    'Person'      [1×1 struct]    [1x1 database.neo4j.Neo4jNode]
    3    'Person'      [1×1 struct]    [1x1 database.neo4j.Neo4jNode]

Access the table of relationships.

relinfo.Relations
ans = 

         StartNodeID    RelationType    EndNodeID    RelationData
         ___________    ____________    _________    ____________

    3    1              'knows'         3            [1×1 struct]

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.

Retrieve the origin node nodeinfo using the Neo4j® database connection neo4jconn and node identifier nodeid.

nodeid = 3;

nodeinfo = searchNodeByID(neo4jconn,nodeid);

Search for incoming relationships using the Neo4j® database connection neo4jconn and origin node nodeinfo. Refine the search by filtering for the relationship type knows and for nodes at a distance of two or less.

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×4 table]

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

  • Origin -- The node identifier for the specified origin node.

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

  • Relations -- A table containing all matched relationships.

Access the table of nodes.

relinfo.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]

Access the table of relationships.

relinfo.Relations
ans = 

         StartNodeID    RelationType    EndNodeID    RelationData
         ___________    ____________    _________    ____________

    3    1              'knows'         3            [1×1 struct]
    2    2              'knows'         1            [1×1 struct]
    1    0              'knows'         1            [1×1 struct]

Input Arguments

collapse all

Neo4j database connection, specified as a Neo4jConnect object created using the function neo4j.

Origin node information, specified as a Neo4jNode object or numeric scalar that denotes a node identifier.

Data Types: double

Relationship direction, specified as one of these values. The relationships are associated with the specified origin node.

ValueDescription

'in'

Incoming relationship

'out'

Outgoing relationship

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: relinfo = searchRelation(neo4jconn,nodeinfo,'in','RelationTypes',{'knows'},'Distance',2);

collapse all

Relationship types, specified as a comma-separated pair consisting of 'RelationTypes' and a cell array of character vectors or string array. To denote one relationship, specify one character vector or string scalar in the cell array. To denote multiple relationships, specify a string array or multiple character vectors in the cell array.

Example: 'RelationTypes',{'knows'}

Data Types: cell | string

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 less than four nodes away from the origin node nodeinfo.

Example: 'Distance',3

Data Types: double

Output Arguments

collapse all

Relationship information in the Neo4j database that matches the search criteria from the origin node nodeinfo, returned as a structure with these fields.

FieldDescription

Origin

Node identifier of the origin node nodeinfo.

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.

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.

Introduced in R2016b

Was this topic helpful?