I'm trying to build this model in Neo4j http://blog.neo4j.org/2012/02/modeling-multilevel-index-in-neoj4.html
Now i need a query to find out if a timeline path already exist. The problem is that i can't seem to make a node optional and at the same time check if a property exist.
Ideally i would like this query:
START a=node(2)
MATCH a:timeline -[?]-> b:time_year -[?]-> c:time_month -[?]-> d:time_day
WHERE b.year = 2013 AND c.month = 7 AND d.day = 28
RETURN b, c, d
But since labels on optional nodes don't seem to be supported i'm going with this query:
START a=node(2)
MATCH a:timeline -[?]-> b -[?]-> c -[?]-> d
WHERE b.year = 2013 AND c.month = 7 AND d.day = 28
RETURN b, c, d
Without the WHERE clause this would return:
a b c
null null null
The result is fine because then i know i have to make a year, month and day node. But without the WHERE clause i can't specify the date i want rendering the entire query useless.
I'm using Neo4j 2.0.0-M03
UPDATE: To clarify why the labels are not working. This is run on a fresh database.
In console:
neo4j-sh (0)$ CREATE (n:timeline) RETURN n;
==> +-----------+
==> | n |
==> +-----------+
==> | Node[1]{} |
==> +-----------+
==> 1 row
==> Nodes created: 1
==> Labels added: 1
==> 967 ms
neo4j-sh (0)$ START a=node(1) MATCH a:timeline -[?]-> b:time_year -[?]-> c:time_month -[?]-> d:time_day WHERE b.year = 2013 AND c.month = 7 AND d.day = 28 RETURN b as year, c as month, d as day;
==> Unrecognized option '['
In data browser:
START a=node(1) MATCH a:timeline -[?]-> b:time_year -[?]-> c:time_month -[?]-> d:time_day WHERE b.year = 2013 AND c.month = 7 AND d.day = 28 RETURN b as year, c as month, d as day;
Returned 0 rows. Query took 138ms
Not found
There is no data matching your query in the database.
I just found out that these queries work in my code, but not in the Neo4j console or data browser. I assumed those would be "flawless" and thus didn't test these queries in my code before. Also it's weird that the console and data browser give different results. Choosing node(*) at start instead of node(1) doesn't make a difference.
Update 2: I played around a little more with the example gists as posted by Peter Neubauer. The problem is that this example returns every or nothing. While i want to make the returned columns optional. So in this example i would like Query3 to return:
Columns: year, month, day
Data: 2010, null, null
But it returns:
Query took 264 ms and returned no rows.
When i make the properties optional like this:
START a=node(*)
MATCH a:timeline -[?]-> b:time_year -[?]-> c:time_month -[?]-> d:time_day
WHERE b.year? = 2010 AND c.month? = 1 AND d.day? = 1
RETURN b AS year, c AS month, d AS day
I get (on the gists website):
Error: java.lang.NullPointerException
Here is the kicker: This only happens on firefox, on chrome this returns: Query took 1 ms and returned no rows.
Then this query:
START a=node(*)
MATCH a:timeline -[?]-> b -[?]-> c -[?]-> d
WHERE b.year? = 2010 AND c.month? = 1 AND d.day? = 1
RETURN b AS year, c AS month, d AS day
Returns:
Columns: year, month, day
Data: (9:time_year {name:"Year 2010", year:2010}), [empty table cell], [empty table cell]
This is the result i want (but then with not making use of labels)
Then the same query on Chrome:
Query took 4 ms and returned no rows.
So my conclusion thus far is:
There are 5 different environments giving different results:
- My own code making using of php4neoj by jadell
- The web interface with using the data browser
- The web interface with using the console
- The gists website http://gist.neo4j.org with using Firefox
- The gists website http://gist.neo4j.org with using Chrome
I have not tried yet:
- The console starting with the batch file
- The gists website http://gist.neo4j.org with using Opera
- The neo4j console at http://console.neo4j.org/ (i expect this to give the same results as the gists because it looks the same, but i haven't test this yet)
So i have a bunch of variations on the queries and a bunch of environments. Perhaps this could be scriptable in a way to have the query run in the different environments and give back the results. Then i could put the results in a table where one axis is the environment and the other one is the query under test.