# How do you do a fully small subgraph search? (Screenshot inside)

I'm creating a database of math diagrams (in a certain category), and need to search for every square say like the above. But these diagrams can get huge maybe 5 x 5 squares, yet they remain relatively sparse.

How can I search for a subgraph using neo4j? It would be great to use Neo4j for this. Thank you.

I already have diagrams like the above being programatically put into a Neo4j database. It's awesome!

So any query's you have I can try out. I'd also like to search using regex template on each label if possible. So for instance $\text{Hom}({var}, {var})$ where {var} can be anything. That way diagrams that are the same except for a relabeling will be counted as equal.

A simple search would be for the diagram pictured would be ...

match pathx = (h:Hom)<--(:ANode)<--(start:CNode)-->(:DNode)-->(h)
return pathx


Note that the (h:Hom) at the start of the path and (h) at the end of the path refer to the same node in order to complete the "square".

You could also specify the relationship types as follows

match pathx = (h:Hom)<-[:alink]-(:ANode)<-[:blink]-(start:CNode)-[:clink]->(:DNode)-[:dlink]->(h)
return pathx


Here is a more detailed article on searching for rings in datasets ...

I'll post another reply later with a more general query for 5x5 etc ...

1 Like