Are you sure that twitter.txt is on your classpath and you're not getting a FileNotFoundException
? You might want to check that first. If the FileReader
can't find your file, no nodes and relationships will be created.
Although I'm not really sure why your example does not work, I do have a couple of suggestions. First of all, I'd get rid of the "id" property as it's very confusing. Every node already has an id so you'd want to change the property name to something else. Second of all, since you are clearly using java 7, you can make use of the AutoClosable
interface of FileReader
and BufferedReader
as well.
When I run the JavaQuery class, I do get the expected results. It's again really strange that your experiencing different behavior. Why don't you try the simplest example of them all? See what output you get from the following script:
public class TestNeo4j {
public static void main(String[] args) throws Exception {
final GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase("db");
final Transaction tx = graphDb.beginTx();
final Node node = graphDb.createNode();
node.setProperty("test", "test");
tx.success();
tx.close();
final ExecutionEngine engine = new ExecutionEngine(graphDb);
System.out.println(engine.execute("START n=node(*) RETURN id(n), n.test").dumpToString());
graphDb.shutdown();
}
}
Your output should be similar to:
+----------------+
| id(n) | n.test |
+----------------+
| 0 | "test" |
+----------------+
1 row
Let me know your results.
EDIT:
If you want to create unique nodes (or paths), use Cyphers MERGE command. It can create unique nodes and/or full paths. An example:
MERGE (tweep1:Tweep{user: "twitter_account"})
MERGE (tweep1)-[:FOLLOWS]->(tweep2:Tweep{user: "another_account"})
This will create or use node "tweep1" if there is already a matching node. That node will be used to create a relationship to node "tweep2". Does this more or less answer your question?