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.

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 a Neo4j® database connection. The search starts from the origin node. To find an origin node, use searchNode or searchNodeByID.

example

relinfo = searchRelation(neo4jconn,nodeinfo,direction,Name,Value) specifies additional options using one or more name-value pair arguments. For example, 'RelationTypes',{'works with'} returns information for relationships that have the type works with.

Examples

collapse all

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 values 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.

neo4jconn.Message
ans =

     []

The blank Message property indicates a successful connection.

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 node

  • Nodes -- A table containing all start and end nodes for each matched relationship

  • Relations -- 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.Neo4jNode]
    3     'Person'     [1×1 struct]    [1x1 database.neo4j.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.Neo4jRelation]

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 values 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.

neo4jconn.Message
ans =

     []

The blank Message property indicates a successful connection.

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 node

  • Nodes -- A table containing all start and end nodes for each matched relationship

  • Relations -- 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.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 =

  3×5 table

         StartNodeID    RelationType    EndNodeID    RelationData              RelationObject          
         ___________    ____________    _________    ____________    __________________________________

    3         1           'knows'           3        [1×1 struct]    [1x1 database.neo4j.Neo4jRelation]
    2         2           'knows'           1        [1×1 struct]    [1x1 database.neo4j.Neo4jRelation]
    1         0           'knows'           1        [1×1 struct]    [1x1 database.neo4j.Neo4jRelation]

Input Arguments

collapse all

Neo4j database connection, specified as a Neo4jConnect object created with 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 either 'in' for an incoming relationship or 'out' for an outgoing relationship. The relationships are associated with the specified origin node.

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 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) 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.

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

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

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 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 that represents each matched database node

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

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.

Introduced in R2016b