Reputation: 15002
The model is for recording all the browse history
How could I summation/average/find_max/find_min
for all the pages browse to page 2
The expected answers are
page2
: 100+200+300+500page2
: 500page2
: 100page1
to page2
: 100Could Anyone give me some queries to achieve the above questions.
The cypher query syntax is really pianful for me.
page1 = Node("Page", name="page1")
page2 = Node("Page", name="page2")
page3 = Node("Page", name="page3")
graph_db.create(neo4j.Path(page1, ("LINKS_TO", {"browsed_time": 200}), page2))
graph_db.create(neo4j.Path(page1, ("LINKS_TO", {"browsed_time": 100}), page2))
graph_db.create(neo4j.Path(page1, ("LINKS_TO", {"browsed_time": 300}), page2))
graph_db.create(neo4j.Path(page3, ("LINKS_TO", {"browsed_time": 500}), page2))
Upvotes: 0
Views: 314
Reputation: 20185
A simple example, you'll need to adapt to match exactly your needs, test console here : http://console.neo4j.org/?id=rs4ado
Example 1: Summing all the relationships properties keyed "time" :
MATCH (p:Page { id:2 })<-[r:LINKS_TO]-(referer)
RETURN sum(r.time) AS totalTime
For average, replace sum
by avg
, same for min
and max
.
Example 2: If you need to get the page node that is linked to Page2, here get the one with the most time, so sort relationship time property in descending order
MATCH (p:Page { id:2 })
MATCH (p)<-[r:LINKS_TO]-(referer)
WITH r
ORDER BY r.time DESC
LIMIT 1
RETURN startNode(r), r.time
Upvotes: 1