Neo4j Cypher Query Builder

I am trying to find a query designer for the Neo4j Cypher query language, ideally using a free API. I did not find much and decided to spend some time creating it.

The result is still a smooth API request builder for the Cypher 1.9 specification.

I wanted to use StackOverflow to start the discussion and see what those thoughts were before I let go of the code.

Here is a demo request that you want to send to Neo4j using Cypher.

Show me all the people who know John, who know Googleโ€™s software engineers (Google code counts 12345). The strength of the relationship between John and the people who connect him with Google employees should be at least 3 (with a range of 1 to 5). Bring back all of Johnโ€™s connections with the people they know on Google, including the relationship between these people. Sort the results by John compound names in ascending order, and then by relationship strength in descending order.

Using Fluent-Cypher:

Cypher .on(Node.named("john").with(Index.named("PERSON_NAMES").match(Key.named("name").is("John")))) .on(Node.named("google").with(Id.is(12345))) .match(Connection.named("rel1").andType("KNOWS").between("john").and("middle")) .match(Connection.named("rel2").andType("KNOWS").between("middle").and("googleEmployee")) .match(Connection.withType("WORKS_AT").from("googleEmployee").to("google")) .where(Are.allOfTheseTrue(Column.named("rel1.STRENGTH").isGreaterThanOrEqualTo(3) .and(Column.named("googleEmployee.TITLE").isEqualTo("Software Engineer")))) .returns(Columns.named("rel1", "middle", "rel2", "googleEmployee")) .orderBy(Asc.column("middle.NAME"), Desc.column("rel1.STRENGTH")) 

which gives the following query:

 START john=node:PERSON_NAMES(name='John'),google=node(12345) MATCH john-[rel1:KNOWS]-middle,middle-[rel2:KNOWS]-googleEmployee,googleEmployee-[:WORKS_AT]->google WHERE ((rel1.STRENGTH >= '3' AND googleEmployee.TITLE = 'Software Engineer')) RETURN rel1,middle,rel2,googleEmployee ORDER BY middle.NAME ASC,rel1.STRENGTH DESC 
+7
neo4j cypher dsl fluent query-builder
source share
2 answers

I agree that you should build this with an eye on Cypher 2.0. Starting with version 2.0, it is very important that WHERE clauses are matched with the correct START , (OPTIONAL) MATCH and WITH (OPTIONAL) MATCH , which make the design of a free API a little more complicated.

+1
source share

I like your first example where you just use text to describe the request. The second option, to tell you the truth, does not look much easier to me than the Cypher request itself. The language is fairly easy to use and well documented. Adding another level of abstraction would only increase complexity. However, if you find a way to translate this query into natural language into a Cypher query, that would be cool :)

Also, why not get started working directly with Cypher 2.0?

Finally, look here: http://github.com/noduslabs/infranodus - I am working on a similar problem, but to add nodes to the database without querying them. I decided to use #hashtags so that people can understand how their requests should be structured (as we already use them). So in your case, it could become something like

 @show-all #people who #John :knows who :know #software-engineers :at #Google. @relationship-strength between #John and the #people who are @linked to #Google #software-engineers should be at least @3 @return @all of #John @connections and the #people they :know at #Google, including the @relationships-between those #people. @sort the @results @by-name of #John @connections in @ascending order and then by @relationship-strength in @descending order. 

(say #hashtags refer to nodes, @at refers to actions on them)

If you could pull something like that, I think it would be much better and more convenient to simplify the already easy to use Cypher.

0
source share

All Articles