Skip to content

Commit af37dd4

Browse files
committed
feat: update neo4jquery builder
Signed-off-by: Otavio Santana <[email protected]>
1 parent c2ec503 commit af37dd4

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

jnosql-neo4j/src/main/java/org/eclipse/jnosql/databases/neo4j/communication/Neo4JQueryBuilder.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private void createWhereClause(StringBuilder cypher, CriteriaCondition condition
111111
case CONTAINS:
112112
case IN:
113113
String paramName = INTERNAL_ID.equals(fieldName) ? "id" : fieldName; // Ensure valid parameter name
114-
parameters.put(paramName, element.get());
114+
parameters.put(paramName, value(element.get(), condition.condition()));
115115
cypher.append(queryField).append(" ")
116116
.append(getConditionOperator(condition.condition()))
117117
.append(" $").append(paramName);
@@ -139,6 +139,13 @@ private void createWhereClause(StringBuilder cypher, CriteriaCondition condition
139139
}
140140
}
141141

142+
private Object value(Object value, Condition condition) {
143+
if(Condition.LIKE.equals(condition)) {
144+
return toCypherRegex(value.toString());
145+
}
146+
return value;
147+
}
148+
142149
private String translateField(String field) {
143150
if (INTERNAL_ID.equals(field)) {
144151
return "elementId(e)";
@@ -149,15 +156,14 @@ private String translateField(String field) {
149156
return "e." + field;
150157
}
151158

152-
153159
private String getConditionOperator(Condition condition) {
154160
return switch (condition) {
155161
case EQUALS -> "=";
156162
case GREATER_THAN -> ">";
157163
case GREATER_EQUALS_THAN -> ">=";
158164
case LESSER_THAN -> "<";
159165
case LESSER_EQUALS_THAN -> "<=";
160-
case LIKE -> "CONTAINS";
166+
case LIKE -> "=~";
161167
case IN -> "IN";
162168
case AND -> "AND";
163169
case OR -> "OR";

jnosql-neo4j/src/test/java/org/eclipse/jnosql/databases/neo4j/communication/Neo4JDatabaseManagerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ void shouldSelectLike() {
321321
var entity = getEntity();
322322
entity.add("name", "Ada Lovelace");
323323
entityManager.insert(entity);
324-
var query = select().from(COLLECTION_NAME).where("name").like("Love").build();
324+
var query = select().from(COLLECTION_NAME).where("name").like("%Love%").build();
325325
var entities = entityManager.select(query).toList();
326326
SoftAssertions.assertSoftly(softly -> {
327327
softly.assertThat(entities).hasSize(1);

0 commit comments

Comments
 (0)