Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lower in operator to enable searching by lower collection values #227

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import jakarta.persistence.criteria.Path;
import jakarta.persistence.criteria.Predicate;
import java.util.Collection;
import java.util.Locale;
import java.util.Objects;

// TODO check if other operators are required
Expand Down Expand Up @@ -95,6 +96,17 @@ public Predicate asPredicate(CriteriaBuilder criteriaBuilder, Path<?> path, Obje

((Collection<?>) value).forEach(inClause::value);

return inClause;
}
},

LOWER_IN {
@Override
public Predicate asPredicate(CriteriaBuilder criteriaBuilder, Path<?> path, Object value) {
CriteriaBuilder.In<String> inClause = criteriaBuilder.in(criteriaBuilder.lower((Expression<String>) path));

((Collection<?>) value).forEach(item -> inClause.value(((String) item).toLowerCase(Locale.ROOT)));

return inClause;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,24 @@ void shouldSupportSearchingByPropertyList() {
assertThat(results).hasSize(2);
}

@Test
void shouldSupportSearchingByPropertyListUsingLowerOperator() {
// given
TestEntitySearchRequest request = new TestEntitySearchRequest(null);
request.setNameSearchList(List.of("firsT1", "First2"));

SearchConfiguration<TestEntity, TestEntity, TestEntitySearchRequest> searchConfiguration = SearchConfiguration.<TestEntity, TestEntity, TestEntitySearchRequest>builder()
.searchOperatorOverrideList(List.of(SearchOperatorOverride.forPath("name", DefaultSearchOperator.LOWER_IN)))
.build();


// when
List<TestEntity> results = executeQuery(request, searchConfiguration);

// then
assertThat(results).hasSize(2);
}

@Test
void shouldIgnoreEmptyCollectionWhenSearching() {
// given
Expand Down
Loading