简体   繁体   中英

Cypher loop over results

I have companies that have logged in and created a relations of debt to other companies . I want to make a query to ask who has created relations (get the first nodes in a relation)

I do it like this

ExecutionEngine engine = new ExecutionEngine(graphDB);
ExecutionResult result = engine.execute( "start n=node(*) match n-[r]->()  return distinct n.name");

When I do

out.println("Companies that have entered data "+result.toString()); 

I get what I wanted, but now I need to display it in the right way for my servlet. I currently do it like this

Iterator<Node> list_companies = result.columnAs("n.name");
while(list_companies.hasNext()){
    Node compan = list_companies.next();
    out.println(compan.getId()+" "+compan.getProperty("name"));
}

And I get no results. My nodes have properties name, tax number and email. I do not think that the right way to do it is to parse

result.toString()

by removing " | +---||"...

If you are returning n.name then you'll have a property returned and not a Node:

Iterator<Node> list_companies = result.columnAs("n.name"); 

should most likely be:

Iterator<String> list_companies = result.columnAs("n.name");
while(list_companies.hasNext()){
    String compan = list_companies.next();
    out.println(compan);
}

If you want the id and the name properties then you could return distinct n and then it would be a Node iterator as in your example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM