Skip to content

Commit 53fd118

Browse files
GH-2274 - Honor ignoreCase() from Sort.Order.
This fixes #2274.
1 parent 7dc6d40 commit 53fd118

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/main/java/org/springframework/data/neo4j/repository/query/CypherAdapterUtils.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
import org.apiguardian.api.API;
2323
import org.neo4j.cypherdsl.core.Cypher;
24+
import org.neo4j.cypherdsl.core.Expression;
25+
import org.neo4j.cypherdsl.core.Functions;
2426
import org.neo4j.cypherdsl.core.SortItem;
2527
import org.neo4j.cypherdsl.core.StatementBuilder;
2628
import org.springframework.data.domain.Pageable;
@@ -49,7 +51,11 @@ public static Function<Sort.Order, SortItem> sortAdapterFor(NodeDescription<?> n
4951
String property = nodeDescription.getGraphProperty(order.getProperty())
5052
.map(GraphPropertyDescription::getPropertyName).orElseThrow(() -> new IllegalStateException(
5153
String.format("Cannot order by the unknown graph property: '%s'", order.getProperty())));
52-
SortItem sortItem = Cypher.sort(property(Constants.NAME_OF_ROOT_NODE, property));
54+
Expression expression = property(Constants.NAME_OF_ROOT_NODE, property);
55+
if (order.isIgnoreCase()) {
56+
expression = Functions.toLower(expression);
57+
}
58+
SortItem sortItem = Cypher.sort(expression);
5359

5460
// Spring's Sort.Order defaults to ascending, so we just need to change this if we have descending order.
5561
if (order.isDescending()) {

src/test/java/org/springframework/data/neo4j/integration/imperative/RepositoryIT.java

+17
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,23 @@ void findAllWithSortByOrderDesc(@Autowired PersonRepository repository) {
339339
assertThat(persons).containsExactly(person2, person1);
340340
}
341341

342+
@Test // GH-2274
343+
void findAllWithSortWithCaseIgnored(@Autowired PersonRepository repository) {
344+
345+
try (Session session = createSession()) {
346+
session.writeTransaction(tx -> {
347+
tx.run("CREATE (n:PersonWithAllConstructor {name: 'Ab', firstName: 'n/a'})");
348+
tx.run("CREATE (n:PersonWithAllConstructor {name: 'aa', firstName: 'n/a'})");
349+
return null;
350+
});
351+
}
352+
353+
List<PersonWithAllConstructor> persons = repository.findAll(Sort.by(Sort.Order.asc("name").ignoreCase()));
354+
assertThat(persons)
355+
.extracting(PersonWithAllConstructor::getName)
356+
.containsExactly("aa", "Ab", "Test", "Test2");
357+
}
358+
342359
@Test
343360
void findAllWithPageable(@Autowired PersonRepository repository) {
344361

0 commit comments

Comments
 (0)