0

I need a Spring Data Neo4J repository method which takes as input a list of names and returns all nodes with a specific label which have one of those names, with depth 1.

For example:

Set<Person> findAllByName(Set<String> names)

should return a Set containing all Persons whose names are in the "names" Set including all their immediate children nodes.

I am open to writing custom queries, filters or anything else, I just want to get this to work somehow.

I already tried writing a custom repository implementation using Neo4jOperations.loadAllByProperties, but I cannot figure out how to create a filter which matches against a list.

Thanks, Alex

1 Answers1

1

You can use a cypher query like the following in your repository:

@Query( "MATCH (a:Person) "+
        "WHERE a.personId IN {0} " +
        "RETURN a ")
List<Person> getPersonList(Set<String> personSet);

Then just call the repository query in your controller:

List<Person> listPerson = personRepository.getPersonList(names);

EDIT: since you want the relationships of Person to also be populated, something like the following could work, based on this blog entry:

@Query( "MATCH (a:Person) "+
        "WHERE a.personId IN {0} "+
        "WITH a "+
        "MATCH p=(a)-[r*0..1]-()"+
        "RETURN a, nodes(p), rels(p)")
List<Person> getPersonList(Set<String> personSet);
Sevle
  • 3,109
  • 2
  • 19
  • 31
  • That doesn't handle the depth part. I need the Persons in the response to have all the relationships populated (depth 1) – Alex Petroaica Jun 29 '16 at 13:09
  • That's correct. Based on the `Map all related entities` section of [this](http://graphaware.com/neo4j/2016/04/06/mapping-query-entities-sdn.html) blog post perhaps my edit would work. Unfortunately, I can't test it myself at the moment. – Sevle Jun 30 '16 at 10:04