I'm new to Cypher-DSL and starting to build some dynamic queries in Spring Neo4J.
I see in the documentation that you can use equalsIgnoreCase for Querydsl Predicate
Predicate predicate = user.firstname.equalsIgnoreCase("dave")
.and(user.lastname.startsWithIgnoreCase("mathews"));
As I want to use projections, how would I do the equalsIgnoreCase for the key
property value below?
Node p = Cypher.node("Entity").named("p");
StatementBuilder.OngoingReadingAndReturn cypher = Cypher
.match(p)
.where(p.property("key").isEqualTo(Cypher.literalOf(key)))
.returning(p);
return cypher;
akollegger1
(Andreas Kollegger)
September 23, 2021, 7:25am
2
Hi,
I think you can turn a Predicate
into a Cypher condition which should be acceptable to the where
clause. Looking at The Neo4j Cypher-DSL
Re-using your two code-snippets, you should be able to do something like:
Predicate predicate = user.firstname.equalsIgnoreCase("dave")
.and(user.lastname.startsWithIgnoreCase("mathews"));
Node p = Cypher.node("Entity").named("p");
StatementBuilder.OngoingReadingAndReturn cypher = Cypher
.match(p)
.where(Cypher.adapt(predicate).asCondition())
.returning(p);
return cypher;
The challenge is what happens with that specific equalsIgnoreCase()
, how it is translated into Cypher. If it works, it would have to turn the equalsIgnoreCase into a regular expression in Cypher, as described here: WHERE - Cypher Manual
@michael.simons Am I close?
-ABK
Quite spot on, @abk !
However, you and @surjit.bhachu hit one of the few QueryDSL ops we don't support (equalsIgnoreCase
), but I am gonna fix that. Until then, this works:
QPerson user = QPerson.person;
Predicate predicate = user.firstName.toLowerCase().eq("dave".toLowerCase())
.and(user.lastName.startsWithIgnoreCase("mathews"));
Node p = Cypher.node("Entity").named("p");
String cypher = Cypher
.match(p)
.where(Cypher.adapt(predicate).asCondition())
.returning(p)
.build().getCypher();
assertThat(cypher).isEqualTo("MATCH (p:`Entity`) WHERE toLower(person.firstName) = 'dave' AND toLower(person.lastName) STARTS WITH 'mathews' RETURN p");
Thanks you two for using and working with the Cypher-DSL, that's great!
1 Like
(Oh no, I just duplicated myself by using the Google sign in… Why is this always so hard getting SSO right :( )
Great thanks guys. I'll be posting some more questions while I try to migrate our product to Spring Neo4j 6, bear with me :)