Main Content

Search Graph Database

Search a Neo4j® graph database using functions provided by the MATLAB® interface to Neo4j and the Database Toolbox™ Interface for Neo4j Bolt Protocol. You can explore the graph data and perform graph network analysis using MATLAB directed graphs.

Search Functionality

Search graph data in a Neo4j graph database using different parts of the graph:

  • Search for one or more nodes using searchNode. Search for a node with a specific identifier using searchNodeByID.

  • Search for relationships from an origin node using searchRelation.

  • Search for the entire graph database or a subgraph using searchGraph.

To access the part of the graph database that you want to analyze, combine these functions and explore the graph data in the output arguments.

General and Targeted Search Workflows

You can search a Neo4j graph database in a general or targeted way. A general search starts from a subgraph or the entire graph. A targeted search starts from an origin node and traverses its relationships.

After finding a part of the graph, you can create a MATLAB directed graph and perform graph network analysis.

Conduct General Search

  1. Conduct a general search for a subgraph using searchGraph.

    For example, to find the subgraph graphinfo, enter this code, which assumes a successful Neo4j database connection neo4jconn. The graphinfo output argument is a directed graph.

    nlabel = {'Person'};
    
    graphinfo = searchGraph(neo4jconn,nlabel, ...
        'DataReturnFormat','digraph');
  2. Perform graph network analysis using the digraph object G. For details, see Directed and Undirected Graphs.

    For example, determine the shortest path between nodes using distances.

    d = distances(G);
    

    Or, explore the graph data by executing the searchGraph function without the 'DataReturnFormat' name-value pair argument and accessing the output structure graphinfo.

Conduct Targeted Search

  1. To start your search, find the origin node using searchNode or searchNodeByID.

    For example, to find the origin node nodeinfo, enter this code, which assumes a successful Neo4j database connection neo4jconn and the node identifier 2.

    nodeinfo = searchNodeByID(neo4jconn,2);
    
  2. Search for graph data by using the origin node and searchRelation. Or, if you know the relationship identifier, then use the searchRelationByID function.

    For example, this code assumes that you are searching for incoming relationships. The relinfo output argument is a directed graph.

    relinfo = searchRelation(neo4jconn,nodeinfo,'in','DataReturnFormat','digraph');
    
  3. Perform graph network analysis using the digraph object G. For details, see Directed and Undirected Graphs.

    For example, determine the shortest path between nodes using distances.

    d = distances(G);
    

    Or, explore node information by accessing the output structure nodeinfo. Also, explore relationship information by executing the searchRelation function without the 'DataReturnFormat' name-value pair argument and accessing the output structure relinfo.

See Also

| | | |

Related Topics

External Websites