subquery - How Can I Replicate This SQL Sub Query In Neo4j -
i new neo4j , graph databases, have background in relational databases.
my question request advice on how replicate sql server query efficiently in neo4j.
i starting new project think suited neo4j due number of friend-of-a-friend type relationships have store. using neo4j 1.8.1 , c# write application
one part of project has section has structure comparable twitter, , need help.
i use twitter analogy explain problem:
i have list of text blobs (tweets) , each blob can in 0, 1 or many categories (hash tags). unlike twitter, have users linked 0, 1 or many categories.
i conceive graph looking this:
t = text blob node, c = category node, u = user node
t-------c-------u \_____/ \_____ / \ \ t-------c-------u \_____ \ t-------c-------u _____/ \_____ / \ t u when application running, estimate there 10,000,000 records (i archive more this), 100 categories , 1000 users.
currently have simple sql server database test this:
__________ ______________ ___________ ______________ ________ |text | |textcategory | |category | |usercategory | |user | |----------| |--------------| |-----------| |--------------| |--------| |textid |-------|textid |------|categoryid |-----|userid |----|userid | |text | |categoryid | |name | |categoryid | |name | |dateadded | |dateadded | |-----------| |--------------| |--------| |----------| |--------------|
by copying dateadded field text table textcategory table , adding indexes 2 linking tables, can run following query return text items belonging category user subscribes ordered date:
select t.* text t inner join tc textcategory on tc.textid = b.textid tc.categoryid in ( select categoyid usercategory userid = @userid ) order tc.addeddate in reality page results simplicity, have left out.
how can replicate query in neo4j database efficeintly? sub query possible in cypher?
if used this:
u-[:subscribes_to]->c<-[:belongs_to]-t (my cypher skills still quite infantile)
i scan through text nodes not able use index on user. end checking each text node see if linked user.
if scanned through relationships linked user, not able take advantage of date ordering index on text nodes page results avoid scanning nodes find 10 earliest example.
as have mentioned come rdbms background , still thinking in relational database way, if wrong in theories please let me know.
i think translates quite directly neo. put user nodes in index , query stated:
start u=users(<userid>) match u-[:subscribes_to]->c<-[:belongs_to]-t return t order t.addeddate skip(<skipped>) limit(<pagesize>) unless missed answered already.
Comments
Post a Comment