Skip to content

feature: allow containsNone predicate to take a single element (resol… #546

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Feb 16, 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 @@ -7,8 +7,11 @@
import com.redis.om.spring.search.stream.predicates.tag.EqualPredicate;
import com.redis.om.spring.search.stream.predicates.tag.InPredicate;
import com.redis.om.spring.search.stream.predicates.tag.NotEqualPredicate;
import com.redis.om.spring.util.ObjectUtils;

import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.ToLongFunction;

Expand Down Expand Up @@ -58,6 +61,14 @@ public NotEqualPredicate<E, T> containsNone(T value) {
return new NotEqualPredicate<>(searchFieldAccessor, value);
}

public NotEqualPredicate<E, ?> containsNone(String value) {
if (!ObjectUtils.isCollection(value.getClass())) {
return new NotEqualPredicate<>(searchFieldAccessor, Set.of(value));
} else {
return new NotEqualPredicate<>(searchFieldAccessor, value);
}
}

public Consumer<E> add(Object value) {
return new ArrayAppendAction<>(searchFieldAccessor, value);
}
Expand Down Expand Up @@ -101,5 +112,4 @@ public <R> ArrayPopAction<E, R> remove(Integer index) {
public Consumer<E> trimToRange(Integer begin, Integer end) {
return new ArrayTrimAction<>(searchFieldAccessor, begin, end);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,19 @@ void testFindByTagsContainsNone() {
assertTrue(names.contains("RedisInc"));
}

@Test
void testFindByTagsContainsNoneSingleValue() {
List<String> names = entityStream //
.of(Company.class) //
.filter(Company$.TAGS.containsNone("innovative")) //
.map(Company$.NAME) //
.collect(Collectors.toList());

assertEquals(1, names.size());

assertTrue(names.contains("RedisInc"));
}

@Test
void testFindFirst() {
Optional<Company> maybeCompany = entityStream.of(Company.class) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,20 @@ void testFindByTagsContainsNone() {
assertTrue(names.contains("RedisInc"));
}

@Test
void testFindByTagsContainsNoneSingleValue() {
// The containsNone predicate will wrap the value in a Set if a single value is provided
List<String> names = entityStream //
.of(Company.class) //
.filter(Company$.TAGS.containsNone("innovative")) //
.map(Company$.NAME) //
.collect(Collectors.toList());

assertEquals(1, names.size());

assertTrue(names.contains("RedisInc"));
}

@Test
void testFindFirst() {
Optional<Company> maybeCompany = entityStream.of(Company.class) //
Expand Down
Loading