Best way to filter nodes by different parameters without writing queries for each parameter combination

415 views
Skip to first unread message

Florian B.

unread,
Apr 25, 2013, 2:00:09 PM4/25/13
to ne...@googlegroups.com
I'm implementing a REST API provided by Java application using Spring MVC, Spring Data Neo4j and Neo4j as database. For the beginning the API is read only but the clients should be able to filter nodes by different attributes. 

One type of node for example are activities. An activity has following relations and properties. 

Properties
  • edited date   
  • type  
  • creation date
  • version
Relations
  • organiser
  • attendee 
  • location 
  • topics 
 
So there are many attribues the activities can be filtered for. I started the implementation using Spring Data Neo4j's Query annotations. But I soon realised that this might not be the best way as I have to write a lot of Cypher queries for every possible combination of attribues I want to filter for. All queries were very similar. They started with one start node which is related to the activity, all other filtering happened in the WHERE statement of the query. The best way would be to build up the queries dynamically depending on the attributes the client passes for filtering. But at the moment I don't how to do this and which options I have. I've read something about the Neo's Traversal API, but till now I have no experience with it. 

So what would be the best way to filter activities dynamically depending of the given filter parameter without writing too many queries?    

I hope this question is ok for the group as I think it is to broad for Stackoverflow and would get closed soon. 

Regards,
Florian

Axel Morgner

unread,
Apr 25, 2013, 3:59:24 PM4/25/13
to ne...@googlegroups.com
Hi Florian,

sorry for the brief reply before, was sent from my mobile. Here's the longer answer:

In general, it might be better to model your problem like this:

Nodes:

  • Activity
  • Person
  • Location
  • Topic

Relationships:

  • ATTENDS
  • ORGANISES
  • IS_AT
  • IS_ABOUT
  • HAS_ACTIVITY

The activity type could then be modeled as an additional "kind" property, or use multiply activity node types with inheritance. This is very rough, as I don't have the full picture of your domain model.

And about Structr: It's very similar to Spring Data Neo4j, but much more lightweight with many pre-built components and a (still somewhat experimental) supplemental web framework/CMS GUI. Maybe worth a try. A good starting point is the screencast which shows how to setup a simple project within 10 minutes: http://vimeo.com/53235075

Best regards
Axel

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--

Axel Morgner · ax...@morgner.de · @amorgner

c/o Morgner UG · Hanauer Landstr. 291a · 60314 Frankfurt · Germany
phone: +49 151 40522060 · skype: axel.morgner

structr - Open Source CMS and Web Framework based on Neo4j: http://structr.org - Winner of 2012 Graphie Award for Most Innovative Open Source Graph Application
structr Mailing List and Forum hosted at Google Groups
Graph Database Usergroup "graphdb-frankfurt", sponsored by Neo4j: http://www.meetup.com/graphdb-frankfurt


Michael Hunger

unread,
Apr 25, 2013, 7:14:18 PM4/25/13
to ne...@googlegroups.com
Florian,

you might also look into cypher dsl, which you can use to programmatically create cypher queries (and re-use and store query-parts).

SDN supports it with the CypherDslRepository.

Another option is QueryDSL(.org) which is also integrated with cypher-dsl and allows you to use literals that are generated from your domain classes to create dynamic queries.

The docs on that is quite thin but the tests should get you started:


Florian B.

unread,
Apr 26, 2013, 4:09:35 AM4/26/13
to ne...@googlegroups.com
Thanks for you response. 

Perhaps I haven't expressed myself that clear, but with relation I actually meant relations to other nodes. So my the model for these activities looks like you proposed. My post was more related to the question how to be able to query these activities dynamically without writing too much queries per hand.

Florian B.

unread,
Apr 26, 2013, 4:17:49 AM4/26/13
to ne...@googlegroups.com
Hi Michael,

ah Cypher DSL looks interesting and might be exactly what I was looking for. 

Thx,
Florian
Reply all
Reply to author
Forward
0 new messages