Main Content

searchNode

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

Description

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.

example

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. The blank Message property indicates a successful connection.

neo4jconn.Message
ans =

     []

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

nlabel = 'Person';

nodeinfo = searchNode(neo4jconn,nlabel)
nodeinfo=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]

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. The structure contains one property key and value.

node = nodeinfo.NodeData(1);
node{1}
ans = struct with fields:
    name: 'User1'

Access the node information using the row name as an index. The structure contains one property key and value.

nodeinfo.NodeData{'0'}
ans = struct with fields:
    name: 'User1'

Find the node degree for the first database node in the table. Specify outgoing relationships. There are two outgoing relationships from the first node in the table with relationship type knows.

degree = nodeDegree(nodeinfo.NodeObject(1),'out')
degree = struct with fields:
    knows: 2

Close the database connection.

close(neo4jconn)

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 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. The nodeinfo output argument is a Neo4jNode object that contains node information.

nlabel = 'Person';

nodeinfo = searchNode(neo4jconn,nlabel,'PropertyKey','name', ...
    'PropertyValue','User2')
nodeinfo = 
  Neo4jNode with properties:

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

Access the node information. The structure contains a property key and value for User2.

nodeinfo.NodeData
ans = struct with fields:
    name: 'User2'

Find the node degree of the outgoing relationships. There is one outgoing relationship type knows for User2.

degree = nodeDegree(nodeinfo,'out')
degree = struct with fields:
    knows: 1

Close the database connection.

close(neo4jconn)

Input Arguments

collapse all

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

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

Data Types: char | string

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: nodeinfo = searchNode(neo4jconn,'Person','PropertyKey','name','PropertyValue','User2');

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, returned as a Neo4jNode object for one node or as a table for multiple nodes.

For multiple nodes, the table contains these variables:

  • NodeLabels — Cell array of character vectors that contains the node labels for each database node

  • NodeData — Cell array of structures that contains node information such as property keys

  • NodeObjectNeo4jNode object for each database node

The row names of the table are Neo4j node identifiers of each database node.

Version History

Introduced in R2016b