You could possibly introduce a concept of purchase, which also would be
nodes. Like this:

(user1)--purchased-->(p1)--from_shop-->(shop1)
                                |
                            product
                                |
                                v
                             (pen)

Then to get users who bought pen from shop1 you get a hold of either the
node representing:

* the pen and traverse to purchases and check if the shop is shop1
* shop1 and traverse to purchases and check if the product is pen

Maybe you are able to know which one of pen and shop1 has the least number
of relationships and start from there, just to make it as fast as possible.
If that would become too slow then you could index the "purchase" nodes with
f.ex. {"shop":"shop1", "product":"pen"} and make a compound lucene query to
get back the purchase nodes, extracting the users from each.

2011/6/15 Manav Goel <goyal.ma...@gmail.com>

> Hello,
>
> I am using neo4j as database in my website. I am having problem in deciding
> best way to query the database.
>
> An user buys, lets say pen, from a shop. User and shop are the nodes and
> pen
> is also a node . Relationships are like
>
> User1->buysfrom->shop1
> User1->uses->pen
> buysfrom and uses are relationships.
>
> Now I want to find all other users who buy pen from shop1.
> Some ways which I have thought to get the result.
>
> I start from user1 and move to shop1 node and from there I find all nodes
> with relationship buysfrom incoming to shop1.
> But it will give me all nodes who buys different stuff than pen. In that
> case I have to check all the hits if they uses pen by traversing from user
> to pen node if such relationship exist this user is my answer.
> In my use case if they use pen then they buy from shop1 thats for sure.
>
>
> Another way I can put an attribute pen in relationship buysfrom and index
> relationship using that attribute. But this will give me all the user who
> buys pen from all the shops. Again lots of checking have to de done again
> like for every hit I have to check if shop1 is end node of the hit If yes
> then start node is the answer I need.
>
> Now I need advice if above mentioned schemes are any good and doubts which
> I
> have regarding them are genuine or not?
> I am expecting minimum 40-50k users and lots of reads and writes in my
> system.
>
> I am sorry if this is a very big question at once but I am thinking a lot
> over these algos for past 1 month  and need some advice how neo4j handles
> these things.
>
> --
> Manav Goel
> _______________________________________________
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
>



-- 
Mattias Persson, [matt...@neotechnology.com]
Hacker, Neo Technology
www.neotechnology.com
_______________________________________________
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to