Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-22-2021 03:11 PM
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;
Solved! Go to Solution.
09-23-2021 12:54 AM
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!
09-23-2021 12:25 AM
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 - Neo4j Cypher Manual
@michael.simons Am I close?
-ABK
09-23-2021 12:54 AM
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!
09-23-2021 12:55 AM
(Oh no, I just duplicated myself by using the Google sign in… Why is this always so hard getting SSO right 😞 )
09-23-2021 03:19 AM
Great thanks guys. I'll be posting some more questions while I try to migrate our product to Spring Neo4j 6, bear with me 🙂
All the sessions of the conference are now available online