Cypher query produces incomplete results (neo4j-1.9-SNAPSHOT) - neo4j

I have run into the problem when executing a cypher query against a database "neo4j-1.9-SNAPSHOT" on Windows 7.
The database can be downloaded from the topic in Google Groups.
When I run the fist 2 queries in the web admin console, I do not get node with id ="45" as the first node in the path in the result list.
1) start a = node:my_nodes(label='2826'), b = node:my_nodes(label='2826')
match a-[r1]-b
with a, b, r1
match b-[r2]-c
where c.label = 2826 and r1.label = r2.label and id(r1) <> id(r2)
return id(a), id(b), id(c), id(r1), id(r2);
2) START n0=node:my_nodes(label='2826'), n1=node:my_nodes(label='2826'),
n2=node:my_nodes(label='2826')
MATCH n0-[r0]-n1-[r1]-n2
where r0.label = r1.label and id(r0)<>id(r1)
RETURN id(n0), id(n1), id(n2), id(r0), id(r1);
However, when I run the 3rd query, node with id="45" should definitely be in the result list of the first two queries. Moreover, when checking the database it seems to be the case.
3) start a = node(45), b = node:my_nodes(label='2826')
match a-[r1]-b
with a, b, r1
match b-[r2]-c
where a.label = 2826 and c.label = 2826 and r1.label = r2.label and id(r1) <> id(r2)
return id(a), a.label, id(b), id(c), id(r1), id(r2);
On running the cypher query:
start a = node:my_nodes(label='2826')
return id(a);
node with id="45" is in the index.
Any ideas what can be wrong with the first 2 queries?

Related

How to filter path results based on a specific node with a specific property

enter image description here
I have a query to find the paths between two nodes. Now, I want to find any paths that have a node with a status = 'down'. However, the only query that works is to find paths without any nodes with a status of down.
Here is the query that is able to give me all the paths without a node with a status = 'down'.
MATCH path=((dev)-[r:part_of|CONNECTS*..20]-(dev2))
WHERE dev.hostname = 'fwmc0208-01' AND dev2.hostname = 'cemc0208-01.edg'
WITH nodes(path) AS n
WHERE NONE(node IN n WHERE (node.status IS NOT NULL) and node.status = 'down')
RETURN n
enter image description here
If I replace NONE with ALL, I get zero results. I've tried flipping the status to equal 'up', but this doesn't work either.
You should use the ANY function:
MATCH path=((dev)-[r:part_of|CONNECTS*..20]-(dev2))
WHERE dev.hostname = 'fwmc0208-01' AND dev2.hostname = 'cemc0208-01.edg'
WITH nodes(path) AS n
WHERE ANY(node IN n WHERE (node.status IS NOT NULL) and node.status = 'down')
RETURN n

Bidirectional recursion in neo4j

Cannot find answer online for this. I want to do a recursive query upstream and downstream on protein interaction map. If user enters a protein (protein 'C') and depth N=2, I want to return 2 upstream and 2 downstream proteins in the interaction map and the regulation. However if its upstream then protein 'b' on right side of MATCH needs to come first in the return table and if its downstream direction then protein 'a' on left side of match needs to come first in return table. How can I do this?
For instance this is the bidirection but half of the rows are the wrong order in columns 1 and 3.
MATCH p = (a:Protein { name:'C' })<-[:REGULATES*1..2]->(b:Protein)
WITH *, relationships(p) as r
RETURN nodes(p)[length(p)-1].name AS Protein1, r[length(p)-1] as Regulates, b.name AS Protein2
I can only get what I want with two calls and switching order or RETURN columns.
MATCH p = (a:Protein { name:'C' })-[:REGULATES*1..2]->(b:Protein)
WITH *, relationships(p) as r
RETURN nodes(p)[length(p)-1].name AS Protein1, r[length(p)-1] as Regulates, length(p), b.name AS Protein2
MATCH p = (a:Protein { name:'C' })<-[:REGULATES*1..2]-(b:Protein)
WITH *, relationships(p) as r
RETURN b.name AS Protein1, r[length(p)-1] as Regulates, nodes(p)[length(p)-1].name AS Protein2
Figured it out using functions startNode and endNode. The last() and head() functions are also handy.
MATCH p = (n:Protein { name:'C' })<-[:REGULATES*1..3]->(b:Protein)
WITH *, relationships(p) as rs
RETURN startNode(last(rs)).name as Protein1, last(rs).direction as Regulates, endNode(last(rs)).name as Protein2, length(p)

How to query with two conditions in Neo4j

I am new with Neo4j and I am stucked trying to get a query with two conditions, where I want to get all the "Autors" related to "Pixar" and "Fox". So far I have tried the following two ways:
MATCH (a:Autor)- [:AUTOR_DE]-> (t:Título) -[:PRODUCIDO_POR] ->( p:Productora {Nombre: "Pixar"}),
and
MATCH (a:Autor)- [:AUTOR_DE]-> (t:Título) -[:PRODUCIDO_POR] ->( p:Productora {Nombre: "Fox"}),
return a,p
and
MATCH (a:Autor)- [:AUTOR_DE]-> (t:Título) -[:PRODUCIDO_POR] ->( p:Productora)
WHERE ( (p:Productora) = "Fox" OR (p:Productora) = "Pixar")
return a,p
Thanks in advance
Assuming that a Productora node stores its name in a name property, and that every Productora node has a unique name, this should work:
MATCH (a:Autor)-[:AUTOR_DE]->(:Título)-[:PRODUCIDO_POR]->(p:Productora)
WHERE p.name = "Fox" OR p.name = "Pixar"
WITH a, COLLECT(DISTINCT p) AS ps
WHERE SIZE(ps) = 2
return a, ps
And this should also work:
MATCH (fox:Productora), (pixar:Productora), (a:Autor)
WHERE fox.name = "Fox" AND pixar.name = "Pixar" AND
(a)-[:AUTOR_DE]->(:Título)-[:PRODUCIDO_POR]->(fox) AND
(a)-[:AUTOR_DE]->(:Título)-[:PRODUCIDO_POR]->(pixar)
return a, fox, pixar

How to set enumeration on properties for selected nodes in one cypher statement?

My graph contains a set of nodes which are enumerated using a dedicated field fid. I want to update this enumeration periodically.
My current approach is to reset the enumeration and execute multiple statements that increase the fid for each node.
1. (f:File) set f.fid = -1
for(int i = 0; i < count ; i++) {
2. (f:File) set f.fid = i where id(f) = nodeId
}
I guess it should be possible to execute this task using a single cypher statement using the foreach clause.
MATCH p=(f:File)
FOREACH (n IN nodes(p)| SET f.fid = -1 )
I was looking for something similar to this statement.
MATCH (f:File)
WITH COLLECT(f) AS fs
WITH fs, i = 0
FOREACH (f in fs, i=i+1| SET f.fid = i ) return f.fid, f.name
Based on the following console set : http://console.neo4j.org/r/447qni
The following query seems to do the trick :
MATCH (f:File)
WITH collect(f) as f, count(f) AS c
UNWIND range(0,c-1) AS x
WITH f[x] AS file,x
SET file.iteration = x+1

How do I get list of nodes from calculated shortest path?

My Cypher looks like this:
START source=node(16822), target=node(12449)
MATCH p = allShortestPaths(source-[*]-target)
return p
And I want to write equivalent C# code for this. This is what I've come up till now
var query = client.Cypher
.Start(new { source = sourceNode.Reference, target = targetNode.Reference })
.Match("p = allShortestPaths(source-[*]-target)")
.Return<Node<Data>>("x");
Where Data is the class which has a string property(string ID).
What should i put in place of x to get my result as a list of concatenated IDs which comprises the path.
Cypher 2.0
START source=node(16822), target=node(12449)
MATCH p = allShortestPaths(source-[*]-target)
return nodes(p)
Good old way of executing query was the last resort which i used
CypherQuery query1 = new CypherQuery(#"START m=node(" + sourceNode.Reference.Id.ToString() + "), n=node(" + targetNode.Reference.Id.ToString() + #")
match p = allshortestpaths(m-[*]-n)
return distinct Extract(x in NODES(p): x.NodeId) as paths", paramCollection, CypherResultMode.Set);
var paths = ((IRawGraphClient)client).ExecuteGetCypherResults<List<string>>(query1);

Resources