Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Cypher query for implementing Status updates
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  14 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Abdul Azeez Shaik  
View profile  
 More options Oct 9 2012, 11:48 pm
From: Abdul Azeez Shaik <azeeztechni...@gmail.com>
Date: Wed, 10 Oct 2012 09:18:30 +0530
Local: Tues, Oct 9 2012 11:48 pm
Subject: Cypher query for implementing Status updates

Hi,

Is there any working cypher query to get status updates of friends (for
below model)? (similar to newsfeed in facebook)?
I am using latest SDN and 1.8GA.
In Neo4j documentation, it was given for traversal, am unable to convert it
into cypher query.
If there is any working example code that would be really great.

[image: Inline image 1]

  image.png
37K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Wes Freeman  
View profile  
 More options Oct 10 2012, 12:06 am
From: Wes Freeman <freeman....@gmail.com>
Date: Wed, 10 Oct 2012 00:06:29 -0400
Local: Wed, Oct 10 2012 12:06 am
Subject: Re: [Neo4j] Cypher query for implementing Status updates

Something like? (replace 1 with node id of person)

start n=node(1)
match n-[:friend]->f-[:status]->s
return s
order by s.date;

Wes

On Tue, Oct 9, 2012 at 11:48 PM, Abdul Azeez Shaik <azeeztechni...@gmail.com

  image.png
37K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Abdul Azeez Shaik  
View profile  
 More options Oct 10 2012, 12:18 am
From: Abdul Azeez Shaik <azeeztechni...@gmail.com>
Date: Wed, 10 Oct 2012 09:48:22 +0530
Local: Wed, Oct 10 2012 12:18 am
Subject: Re: [Neo4j] Cypher query for implementing Status updates

Thanks for the prompt response Wes.
NEXT relationship must also be included, as next.status might be the latest
one compared to s.status. struggling here to write a one...

And Lets say, i limit to 20 updates now. Next time when user wants next
list, i need to get next 20updates, by this time,  there might be 10 new
updates, due to this i will get 10old updates(which was already retrieved
in first query).
Is this something that i need to handle after retrieving data?

Thanks,
Abdul

  image.png
37K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Abdul Azeez Shaik  
View profile  
 More options Oct 10 2012, 1:36 am
From: Abdul Azeez Shaik <azeeztechni...@gmail.com>
Date: Wed, 10 Oct 2012 11:06:37 +0530
Local: Wed, Oct 10 2012 1:36 am
Subject: Re: [Neo4j] Cypher query for implementing Status updates

I have written below cypher query is to create Statusupdate,

@Query( "START n=node:search(username={0}) MATCH n-[r:STATUS]->oldsu DELETE
r " +

 "WITH n,oldsu CREATE n-[:STATUS]->(newsu
{statusid:{1},statusUpdate:{2},postedDate:{3}})-[:NEXT]-oldsu")

void newStatusUpdate(String username, String statusid, String statusupdate,
Date createddate);

However, how do i need to take care of is "su" doesn't exist, in that case
second sub-query would not get executed.

Kindly help me.

Thanks,
Abdul

On Wed, Oct 10, 2012 at 9:48 AM, Abdul Azeez Shaik <azeeztechni...@gmail.com

  image.png
37K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Abdul Azeez Shaik  
View profile  
 More options Oct 10 2012, 1:56 am
From: Abdul Azeez Shaik <azeeztechni...@gmail.com>
Date: Wed, 10 Oct 2012 11:25:52 +0530
Local: Wed, Oct 10 2012 1:55 am
Subject: Re: [Neo4j] Cypher query for implementing Status updates

I tried same query with optional relationship in first subquery, first
subquery works fine.
However, second sub-query fails due to null in second query.
Can we avoid creating second relationship in oldsu is null?
Here is the updated query,

@Query( "START n=node:search(username={0}) MATCH n-[r?:STATUS]->oldsu
DELETE r " +

"WITH n,oldsu CREATE n-[:STATUS]->(newsu
{statusid:{1},statusUpdate:{2},postedDate:{3}})-[:NEXT]->oldsu")

void newStatusUpdate(String username, String statusid, String statusupdate,
Date createddate);

On Wed, Oct 10, 2012 at 11:06 AM, Abdul Azeez Shaik <

  image.png
37K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Abdul Azeez Shaik  
View profile  
 More options Oct 10 2012, 2:15 am
From: Abdul Azeez Shaik <azeeztechni...@gmail.com>
Date: Wed, 10 Oct 2012 11:44:45 +0530
Local: Wed, Oct 10 2012 2:14 am
Subject: Re: [Neo4j] Cypher query for implementing Status updates

Ok, got the first part, got confused unnecessarily.
start n=node(1)
match n-[:friend]->f-[:status]->s-[:next*0..]->su
return su
order by su.date desc;

Thanks for providing me initial help Wes.

Any help on the second part,
Lets say, i limit to 20 updates now. Next time when user wants next list, i
need to get next 20updates, by this time,  there might be 10 new updates,
due to this i will get 10old updates(which was already retrieved in first
query).
Is this something that i need to handle after retrieving data?

On Wed, Oct 10, 2012 at 9:48 AM, Abdul Azeez Shaik <azeeztechni...@gmail.com

  image.png
37K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Wes Freeman  
View profile  
 More options Oct 10 2012, 2:34 am
From: Wes Freeman <freeman....@gmail.com>
Date: Wed, 10 Oct 2012 02:34:19 -0400
Local: Wed, Oct 10 2012 2:34 am
Subject: Re: [Neo4j] Cypher query for implementing Status updates

You can do:
start n=node(1)
match n-[:friend]->f-[:status]->s-[:next*0..]->su
return su
order by su.date desc
skip 20
limit 20;

To skip the first 20, and get 20 more status updates. Then you can keep
incrementing skip as you get more.

Wes

On Wed, Oct 10, 2012 at 2:14 AM, Abdul Azeez Shaik <azeeztechni...@gmail.com

  image.png
37K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Abdul Azeez Shaik  
View profile  
 More options Oct 10 2012, 2:50 am
From: Abdul Azeez Shaik <azeeztechni...@gmail.com>
Date: Wed, 10 Oct 2012 12:20:34 +0530
Local: Wed, Oct 10 2012 2:50 am
Subject: Re: [Neo4j] Cypher query for implementing Status updates

Hi Wes,

In between first call and second call if there are 10 more status updates,
then it returns 10new and 10old(which are already return in first call) in
second call.
I am thinking to save posted data from first call and add this condition to
second call so that query doesn't consider new status updates.
Please let me know if this can be implemented in some other way.

Thanks,
 Abdul

  image.png
37K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Wes Freeman  
View profile  
 More options Oct 10 2012, 3:07 am
From: Wes Freeman <freeman....@gmail.com>
Date: Wed, 10 Oct 2012 03:06:45 -0400
Local: Wed, Oct 10 2012 3:06 am
Subject: Re: [Neo4j] Cypher query for implementing Status updates

Are status updates linked together via next? Maybe you should just be
querying based on the oldest status update already returned, and then
following that path. For the new status updates, that should be a different
query (I think).

On Wed, Oct 10, 2012 at 2:50 AM, Abdul Azeez Shaik <azeeztechni...@gmail.com

  image.png
37K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Abdul Azeez Shaik  
View profile  
 More options Oct 10 2012, 4:10 am
From: Abdul Azeez Shaik <azeeztechni...@gmail.com>
Date: Wed, 10 Oct 2012 13:40:24 +0530
Local: Wed, Oct 10 2012 4:10 am
Subject: Re: [Neo4j] Cypher query for implementing Status updates

Thats a nice idea. It would make query too very simple.
Thanks for the help Wes.

Any idea on the other query which i posted on same thread?

I tried same query with optional relationship in first subquery, first
subquery works fine.
However, second sub-query fails due to null in second query.
Can we avoid creating second relationship in oldsu is null?
Here is the updated query,

@Query( "START n=node:search(username={0}) MATCH n-[r?:STATUS]->oldsu
DELETE r " +

"WITH n,oldsu CREATE n-[:STATUS]->(newsu
{statusid:{1},statusUpdate:{2},postedDate:{3}})-[:NEXT]->oldsu"

  image.png
37K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Wes Freeman  
View profile  
 More options Oct 10 2012, 4:20 am
From: Wes Freeman <freeman....@gmail.com>
Date: Wed, 10 Oct 2012 04:19:51 -0400
Local: Wed, Oct 10 2012 4:19 am
Subject: Re: [Neo4j] Cypher query for implementing Status updates

You can use predicates with CREATE also, so just add a WHERE oldsu <> null
at the end.

At least, I think that's what you're trying to do.

Wes

On Wed, Oct 10, 2012 at 4:10 AM, Abdul Azeez Shaik <azeeztechni...@gmail.com

  image.png
37K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Abdul Azeez Shaik  
View profile  
 More options Oct 10 2012, 6:57 am
From: Abdul Azeez Shaik <azeeztechni...@gmail.com>
Date: Wed, 10 Oct 2012 16:27:10 +0530
Local: Wed, Oct 10 2012 6:57 am
Subject: Re: [Neo4j] Cypher query for implementing Status updates

That predicate will exclude the complete operation, CREATE
n-[:STATUS]->(newsu {statusid:{1},statusUpdate:{2}
,postedDate:{3}})-[:NEXT]->oldsu

First relation and node must be created, only second one must get
excluded.i.e.NEXT relation.

Thanks,
Abdul

  image.png
37K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Wes Freeman  
View profile  
 More options Oct 10 2012, 10:02 am
From: Wes Freeman <freeman....@gmail.com>
Date: Wed, 10 Oct 2012 10:02:06 -0400
Local: Wed, Oct 10 2012 10:02 am
Subject: Re: [Neo4j] Cypher query for implementing Status updates

So, this is the closest I can get it:

start n=node:node_auto_index(name="person")
match n-[r?:STATUS]->oldsu
create n-[:STATUS]->(newsu {id:"an id"})
with oldsu, newsu
create newsu-[:NEXT]->oldsu
where oldsu <> null
return newsu;

The trouble with this one is that you can get multiple results back from
the first match, so it will create more than one record with the second
create.

In my latest pull request, there is a way to limit and order after a with
statement, which I think might actually help here:
https://github.com/neo4j/community/pull/913

This way you can do:
start n=node:node_auto_index(name="person")
match n-[r?:STATUS]->oldsu
with oldsu,n
order by oldsu.date desc
limit 1
create n-[:STATUS]->(newsu {id:"an id",date:1000000})
with oldsu, newsu
create newsu-[:NEXT]->oldsu
where oldsu <> null
return newsu;

I tested it on my local build and it creates 1 node and 1 relationship the
first time, and then 1 node and 2 relationships the additional times I run
it.

Maybe Michael or Peter know a better way to do it without the new pull
request.

Wes

On Wed, Oct 10, 2012 at 6:57 AM, Abdul Azeez Shaik <azeeztechni...@gmail.com

  image.png
37K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Abdul Azeez Shaik  
View profile  
 More options Oct 10 2012, 11:58 am
From: Abdul Azeez Shaik <azeeztechni...@gmail.com>
Date: Wed, 10 Oct 2012 21:27:57 +0530
Local: Wed, Oct 10 2012 11:57 am
Subject: Re: [Neo4j] Cypher query for implementing Status updates

Thats awesome Wes. I tried it just now and it worked like champ.
This query also makes sure that there is only one node with 'STATUS
relationship, so, first match always returns single result.

Thanks once again for all the help Wes.

Regards,
 Abdul

  image.png
37K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »