Good one, thanks for sharing that =)

Den måndagen den 31:e mars 2014 kl. 16:02:31 UTC+2 skrev Michael Azerhad:
>
> Thanks Lundin, but...... Wow, you see this part of your query: 
>
> MATCH users-[:ASSOCIATED_TO]->(profile)
>
> it would grab ALL paths  ;) ..let's say I have 2 millions of users, it 
> would get the 2 millions of paths..  (Your query took 3900 ms to execute 
> ...)  Just too long and too heavy
>
> I've just made this query: 
>
> MATCH (u1:User {_id: "691dfb07-1ca3-44ba-9b2b-3807a0629156"}), (u2:User {
> _id: "21149fc5-97ee-45f9-8250-558817c930af"}), knowledgePath =allShortestPaths
> (u1-[r:KNOWS*..4]-(u2))
> WITH nodes(knowledgePath) as knowledgeNodes, u1, u2
> WITH filter(user in knowledgeNodes WHERE user._id <> u1._id AND  user._id 
> <> u2._id) as filteredUsers
> RETURN extract(filteredUser in filteredUsers | extract( p in filteredUser
> -[:ASSOCIATED_TO]->() | last(nodes(p)).firstName + ":" + last(nodes(p)).
> lastName)) as knowledge
>
> (excluding in this case the boundaries (extreme users)). 
>
> It took me an average about 110ms of execution. 
>
> I ended up with this results: 
>
> Bob:SMITH, Alice:SCOTTBob:SMITH, Alexander:FISHER
>
> I use the ":" separator in order to be able to parse them and map them to 
> Java POJO for instance (by splitting the result on ":").
>
> By the way, I said in my first part above:
>
>  Not returning a collection of knowledge (with good properties as 
> expected) at once in one record, but rather distinct records, each one 
> containing (firstName, LastName)
>
>
> It was a nonsense to avoid a collection as a result of each record, since 
> allShortestPaths returns multiple paths.
>
> If someone has a better solution, with pleasure :)
>
> Michael
>
>
> On Monday, March 31, 2014 3:45:14 PM UTC+2, Lundin wrote:
>
> Hi,
>
> Mabey something more simple like this
>
> MATCH (u1:People { name: "MYname" }),(u2:People { name: "myfriend" }), 
> knowledgePath = allShortestPaths(u1-[:KNOWS*..4]-(u2)) WITH nodes(
> knowledgePath) AS knowledgeNodes,u1,u2 MATCH users-[:ASSOCIATED_TO]->(
> profile) WITH profile,knowledgeNodes,u1,u2 WITH extract(users IN 
> knowledgeNodes | profile.name) AS knowledge RETURN DISTINCT head(knowledge
> );
>
> Den måndagen den 31:e mars 2014 kl. 14:46:45 UTC+2 skrev Michael Azerhad:
>
> Hi,
>
> Let's assume this beginning of Cypher query, aiming to retrieve all 
> shortest paths (regarding knowledge) between two users:
>
> MATCH (u1:User {id: "1"}), (u2:User {id: "2"}), knowledgePath 
> =allShortestPaths
> (u1-[:KNOWS*..4]-(u2))
>
> Besides, each User is linked to a UserProfile node in the graph through 
> the relationship ASSOCIATED_TO.
>
> So, what I want is to end up retrieving the UserProfile's firstName 
> property and  UserProfile's lastName property of each knowledge, including 
> the boundaries (the 2 extreme users).
>
> I tried this:
>
> MATCH (u1:User {id: "1"}), (u2:User {id: "2"}), knowledgePath 
> =allShortestPaths
> (u1-[:KNOWS*..<span style=
>
> ...

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to