Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bipartite graph implementation in neo4j

i have a Bipartite graph of users and items. i want to implement this in neo4j. is there any way how to distinguish between the nodes? right now, the only difference is in the property value:

node A properties:
type=user, age=18, name=user123
node B properties:
type=item, price=123, name=item1234

and querying the graph in cypher looks like this:

-get all users:
start n=node:node_auto_index('type:user') return n;
start n=node:node_auto_index('age:*') return n;

1: although, since there is the age property on every user, there is no need to specify the exact node type, is it? do i have to specify it anyway?

2: second, since the type property is completely duplicite, wouldn't it be easier to create 1 specific node with property user, and one specific node with property item, and than relate all user nodes and all item nodes to their adequate root node?

3: is there any way in neo4j, when creating a node, to specify it's type other than creating a node's parameter type ? (something like each group of nodes is saved in a different section in the db and thus querying or picking up the specific group does require just pointing to this area rather than running through all nodes and check for the type parameter)

like image 758
ulkas Avatar asked Nov 04 '22 17:11

ulkas


1 Answers

Well, there is no golden rule. If you have a lot of nodes of one type, you might want to use and index, otherwise and type node is nice too. Depends on your usecase as really big supernodes are slowing down things and are better treated as indexes.

If you know that you have a unique property on a node type, then of course you can infer it from that property, and skip the property type in your case.

like image 153
Peter Neubauer Avatar answered Nov 09 '22 04:11

Peter Neubauer