Reputation: 1811
We have the following scenario: - there are User objects, up to 1 million - there are Car objects of different kinds (let's say there are cars from Mercedes, Ferrari, Porsche, BMW), also up to 1 million objects
With the graph database I can model very easy that User A likes Car B, and I can find very efficiently what cars are liked by User A.
However, how can I efficiently find all user nodes? I have seen the cool Neo4j 2.0 Schema Types, but currently I have to use Neo4j 1.8. Do I have to use a property like "nodeProperty" with a value =user for Users and a value =car for Cars do find them? Is that efficient?
And how can I efficiently run searchs for Cars that are from a certain year and have a certain color? (assuming that Car objects may have this property) Do I have to iterate over all Cars and look for that? Or is the Neo4j idea that I create a Super-Node with all years that appear and I connect all Cars to the according year node?
Upvotes: 0
Views: 131
Reputation: 19373
You can index some property of each user such as a userId to easily find all user nodes (http://docs.neo4j.org/chunked/stable/indexing.html)
For the cars, do you simply wish to search for cars of a certain year and color? Or do you want to use those to do more detailed querying?
If you just want a straight search, then you might consider the index there as well. Otherwise the year nodes and maybe even color nodes would be the way I'd do it. Note that you can use both an index (index on year and color), as well as the year/color nodes. The index might be helpful to find a starting set of nodes before you do more involved querying. If color is important in these queries, then having the car related to a color would be much better than the color as a property on the car (because the property would have to be checked frequently which is less desirable than traversing a relation). As with all modeling queries, depends on what you wish to do with the data. Hope that helps.
Upvotes: 1