Skip to content

Commit 0e01525

Browse files
GH-2274 - Honor ignoreCase() from Sort.Order.
This fixes #2274.
1 parent 6851ba8 commit 0e01525

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-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.neo4j.cypherdsl.core.SymbolicName;
@@ -60,7 +62,11 @@ public static Function<Sort.Order, SortItem> sortAdapterFor(NodeDescription<?> n
6062
String graphProperty = nodeDescription.getGraphProperty(domainProperty)
6163
.map(GraphPropertyDescription::getPropertyName).orElseThrow(() -> new IllegalStateException(
6264
String.format("Cannot order by the unknown graph property: '%s'", order.getProperty())));
63-
SortItem sortItem = Cypher.sort(property(root, graphProperty));
65+
Expression expression = property(root, graphProperty);
66+
if (order.isIgnoreCase()) {
67+
expression = Functions.toLower(expression);
68+
}
69+
SortItem sortItem = Cypher.sort(expression);
6470

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

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

+16
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,22 @@ void findAllWithSortByOrderDesc(@Autowired PersonRepository repository) {
358358
assertThat(persons).containsExactly(person2, person1);
359359
}
360360

361+
@Test // GH-2274
362+
void findAllWithSortWithCaseIgnored(@Autowired PersonRepository repository) {
363+
364+
doWithSession(session ->
365+
session.writeTransaction(tx -> {
366+
tx.run("CREATE (n:PersonWithAllConstructor {name: 'Ab', firstName: 'n/a'})");
367+
tx.run("CREATE (n:PersonWithAllConstructor {name: 'aa', firstName: 'n/a'})");
368+
return null;
369+
}));
370+
371+
List<PersonWithAllConstructor> persons = repository.findAll(Sort.by(Sort.Order.asc("name").ignoreCase()));
372+
assertThat(persons)
373+
.extracting(PersonWithAllConstructor::getName)
374+
.containsExactly("aa", "Ab", "Test", "Test2");
375+
}
376+
361377
@Test
362378
void findAllWithPageable(@Autowired PersonRepository repository) {
363379

0 commit comments

Comments
 (0)