Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paging with Spring Data Graph/Neo4j

Is it possible to fetch Page results when using Spring Data Graph (Neo4J) as the data store?

The findAll(Pageable) seems to be the only Pageable query availalble when using the GraphRepository. What I am looking for is Pageable APIs for other findBy***() like queries.

Perhaps, there may be a completely different (recommended) way to Page results using Spring Data Graph. Thoughts on that are welcome as well!

like image 826
Saket Avatar asked Feb 12 '26 00:02

Saket


1 Answers

Spring Data Neo4j (2.0 currently in SNAPSHOT but soon RC1) added Page support for the derived and annotated queries. The findAll() is inherited from CRUD-Repository.

We could add Page support for the default query methods. Could you raise a JIRA issue for that?

Example for derived and @Query annotated Page methods.

interface UserRepository extends GraphRepository<User> {
   // derived method
   Page<User> findByTag(String tag, Pageable page);
   @Query("start user=node({0}) match user-[r:RATED]-product where r.stars > 3 return product order by r.stars desc")
   Page<Product> getRatedProducts(User user);
}

Just add cypher (or gremlin) as dependency to your application:

<dependency>
   <groupId>org.neo4j</groupId>
   <artifactId>neo4j-cypher</artifactId>
   <version>${neo4j.version}</version>
</dependency>
like image 106
Michael Hunger Avatar answered Feb 15 '26 12:02

Michael Hunger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!