Skip to content

Commit 004abb5

Browse files
author
gustavnavar
committed
Add remove diacritics database support
1 parent f5b7b5f commit 004abb5

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

gridcore/src/main/java/me/agno/gridcore/filtering/types/TextFilterType.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public Predicate getFilterExpression(CriteriaBuilder cb, Root<T> root, String ex
3333

3434
var path = getPath(root, expression);
3535

36-
if(removeDiacritics == null) {
36+
if(removeDiacritics == null || removeDiacritics.isBlank()) {
3737
return switch (filterType) {
3838
case EQUALS -> cb.equal(cb.upper(path), typedValue.toUpperCase());
3939
case IS_NULL -> cb.or(cb.isNull(path), cb.equal(cb.trim(path), ""));
@@ -50,16 +50,18 @@ public Predicate getFilterExpression(CriteriaBuilder cb, Root<T> root, String ex
5050
}
5151
else {
5252
return switch (filterType) {
53-
case EQUALS -> cb.equal(cb.upper(path), typedValue.toUpperCase());
53+
case EQUALS -> cb.equal(cb.function(removeDiacritics, String.class, cb.upper(path)),
54+
cb.function(removeDiacritics, String.class, cb.literal(typedValue.toUpperCase())));
5455
case IS_NULL -> cb.or(cb.isNull(path), cb.equal(cb.trim(path), ""));
55-
case NOT_EQUALS -> cb.notEqual(cb.upper(path), typedValue.toUpperCase());
56+
case NOT_EQUALS -> cb.notEqual(cb.function(removeDiacritics, String.class, cb.upper(path)),
57+
cb.function(removeDiacritics, String.class, cb.literal(typedValue.toUpperCase())));
5658
case IS_NOT_NULL -> cb.and(cb.isNotNull(path), cb.notEqual(cb.trim(path), ""));
57-
case CONTAINS -> cb.like(cb.upper(path),
58-
'%' + typedValue.toUpperCase() + '%');
59-
case STARTS_WITH -> cb.like(cb.upper(path),
60-
typedValue.toUpperCase() + '%');
61-
case ENDS_WIDTH -> cb.like(cb.upper(path),
62-
'%' + typedValue.toUpperCase());
59+
case CONTAINS -> cb.like(cb.function(removeDiacritics, String.class, cb.upper(path)),
60+
cb.function(removeDiacritics, String.class, cb.literal('%' + typedValue.toUpperCase() + '%')));
61+
case STARTS_WITH -> cb.like(cb.function(removeDiacritics, String.class, cb.upper(path)),
62+
cb.function(removeDiacritics, String.class, cb.literal(typedValue.toUpperCase() + '%')));
63+
case ENDS_WIDTH -> cb.like(cb.function(removeDiacritics, String.class, cb.upper(path)),
64+
cb.function(removeDiacritics, String.class, cb.literal('%' + typedValue.toUpperCase())));
6365
default -> throw new IllegalArgumentException();
6466
};
6567
}

gridcore/src/main/java/me/agno/gridcore/searching/DefaultColumnSearch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public Predicate getExpression(CriteriaBuilder cb, Root<T> root, String value, b
3737
'%' + value.toUpperCase() + '%');
3838
}
3939
else {
40-
return cb.like(cb.upper(path.as(String.class)),
41-
'%' + value.toUpperCase() + '%');
40+
return cb.like(cb.function(removeDiacritics, String.class,cb.upper(path.as(String.class))),
41+
cb.function(removeDiacritics, String.class, cb.literal('%' + value.toUpperCase() + '%')));
4242
}
4343
}
4444

0 commit comments

Comments
 (0)