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.

searchNode

Search Neo4j database nodes by label or by property key and value

Syntax

nodeinfo = searchNode(neo4jconn,nlabel)
nodeinfo = searchNode(neo4jconn,nlabel,Name,Value)

Description

example

nodeinfo = searchNode(neo4jconn,nlabel) returns node information for nodes with a specific node label using the Neo4j® database connection neo4jconn.

example

nodeinfo = searchNode(neo4jconn,nlabel,Name,Value) narrows the search for nodes with additional options specified by the 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.

Search the database for nodes that have node label Person using the Neo4j® database connection neo4jconn.

nlabel = 'Person';

nodeinfo = searchNode(neo4jconn,nlabel)
nodeinfo = 

         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]

nodeinfo is a table that contains information for each database node:

  • Each row name is a node identifier.

  • Variable NodeLabels is the node label.

  • Variable NodeData is the node information.

  • Variable NodeObject is the Neo4jNode object.

Access the node information for the first node in the table.

node = nodeinfo.NodeData(1);
node{1}
ans = 

  struct with fields:

    name: 'User1'

The structure contains one property key and value.

Access the node information using the row name as an index.

nodeinfo.NodeData{'0'}
ans = 

  struct with fields:

    name: 'User1'

The structure contains one property key and value.

Find the node degree for the first database node in the table. Specify outgoing relationships.

degree = nodeDegree(nodeinfo.NodeObject(1),'out')
degree = 

  struct with fields:

    knows: 2

There are two outgoing relationships from the first node in the table with relationship 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.

Search the database for nodes that have node label Person using the Neo4j® database connection neo4jconn. Filter the results further by the property key and value for a specific person named User2.

nlabel = 'Person';

nodeinfo = searchNode(neo4jconn,nlabel,'PropertyKey','name', ...
    'PropertyValue','User2')
nodeinfo = 

  Neo4jNode with properties:

        NodeID: 2
      NodeData: [1×1 struct]
    NodeLabels: 'Person'

nodeinfo is a Neo4jNode object that contains node information.

Access the node information.

nodeinfo.NodeData
ans = 

  struct with fields:

    name: 'User2'

The structure contains a property key and value for User2.

Find the node degree of the outgoing relationships.

degree = nodeDegree(nodeinfo,'out')
degree = 

  struct with fields:

    knows: 1

There is one outgoing relationship type knows for User2.

Input Arguments

collapse all

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

Neo4j database node label, specified as a character vector or string scalar.

Data Types: char | string

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: nodeinfo = searchNode(neo4jconn,'Person','PropertyKey','name','PropertyValue','User2');

collapse all

Property key, specified as a comma-separated pair consisting of 'PropertyKey' and a character vector or string scalar. A property key must have a corresponding property value. To specify the property value, use the name-value pair argument 'PropertyValue'.

Example: 'PropertyKey','name'

Data Types: char | string

Property value, specified as a comma-separated pair consisting of 'PropertyValue' and a character vector or string scalar. A property value must have a corresponding property key. To specify the property key, use the name-value pair argument 'PropertyKey'.

Example: 'PropertyValue','User1'

Data Types: char | string

Output Arguments

collapse all

Node information in the Neo4j database that matches the search criteria, returned as a Neo4jNode object for one node or a table for multiple nodes.

For multiple nodes, the table contains:

  • Row names, which are Neo4j node identifiers of each database node.

  • The variable NodeLabels, which is a cell array of character vectors that contains the node labels for each database node.

  • The variable NodeData, which is a cell array of structures that contain node information such as property keys.

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

Introduced in R2016b

Was this topic helpful?