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

In nin array subdoc #737

Merged
merged 21 commits into from
Dec 19, 2023
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 @@ -411,25 +411,59 @@ public List<BuiltCondition> getAll() {
switch (operator) {
case IN:
if (values.isEmpty()) return List.of();
return values.stream()
.map(
v ->
BuiltCondition.of(
DATA_CONTAINS,
Predicate.CONTAINS,
new JsonTerm(getHashValue(new DocValueHasher(), getPath(), v))))
.collect(Collectors.toList());
final ArrayList<BuiltCondition> inResult = new ArrayList<>();
for (Object value : values) {
if (value instanceof Map) {
// array element is sub_doc
inResult.add(
BuiltCondition.of(
BuiltCondition.LHS.mapAccess("query_text_values", Values.NULL),
Predicate.EQ,
new JsonTerm(this.getPath(), getHash(new DocValueHasher(), value))));
} else if (value instanceof List) {
// array element is array
inResult.add(
BuiltCondition.of(
BuiltCondition.LHS.mapAccess("query_text_values", Values.NULL),
Predicate.EQ,
new JsonTerm(this.getPath(), getHash(new DocValueHasher(), value))));
} else {
inResult.add(
BuiltCondition.of(
DATA_CONTAINS,
Predicate.CONTAINS,
new JsonTerm(getHashValue(new DocValueHasher(), getPath(), value))));
}
}
return inResult;
case NIN:
if (values.isEmpty()) return List.of();
if (!this.getPath().equals(DOC_ID)) {
return values.stream()
.map(
v ->
BuiltCondition.of(
DATA_CONTAINS,
Predicate.NOT_CONTAINS,
new JsonTerm(getHashValue(new DocValueHasher(), getPath(), v))))
.collect(Collectors.toList());
final ArrayList<BuiltCondition> ninResults = new ArrayList<>();
for (Object value : values) {
if (value instanceof Map) {
// array element is sub_doc
ninResults.add(
BuiltCondition.of(
BuiltCondition.LHS.mapAccess("query_text_values", Values.NULL),
Predicate.NEQ,
new JsonTerm(this.getPath(), getHash(new DocValueHasher(), value))));
} else if (value instanceof List) {
// array element is array
ninResults.add(
BuiltCondition.of(
BuiltCondition.LHS.mapAccess("query_text_values", Values.NULL),
Predicate.NEQ,
new JsonTerm(this.getPath(), getHash(new DocValueHasher(), value))));
} else {
ninResults.add(
BuiltCondition.of(
DATA_CONTAINS,
Predicate.NOT_CONTAINS,
new JsonTerm(getHashValue(new DocValueHasher(), getPath(), value))));
}
}
return ninResults;
} else {
// can not use stream here, since lambda parameter casting is not allowed
List<BuiltCondition> conditions = new ArrayList<>();
Expand All @@ -453,7 +487,7 @@ public List<BuiltCondition> getAll() {
} else {
throw new JsonApiException(
ErrorCode.UNSUPPORTED_FILTER_DATA_TYPE,
String.format("Unsupported $nin operand value: %s", docIdValue));
String.format("Unsupported _id $nin operand value: %s", docIdValue));
}
}
}
Expand Down
Loading