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

fix: query mismatch with non-intersecting OR and nested AND condition #5452

Merged
merged 2 commits into from Mar 6, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions api/src/main/java/run/halo/app/extension/index/query/And.java
Expand Up @@ -25,8 +25,6 @@ public NavigableSet<String> matches(QueryIndexView indexView) {
NavigableSet<String> resultSet = null;
for (Query query : childQueries) {
NavigableSet<String> currentResult = query.matches(indexView);
// Trim unneeded rows to shrink the dataset for the next query
indexView.removeByIdNotIn(currentResult);
if (resultSet == null) {
resultSet = Sets.newTreeSet(currentResult);
} else {
Expand Down
19 changes: 19 additions & 0 deletions api/src/test/java/run/halo/app/extension/index/query/AndTest.java
Expand Up @@ -94,4 +94,23 @@ void andMatch2() {
var resultSet = query.matches(indexView);
assertThat(resultSet).containsExactly("100");
}

@Test
void orAndMatch() {
var indexView = IndexViewDataSet.createEmployeeIndexView();
// test the case when the data matched by the query does not intersect with the data
// matched by the and query
// or(query, and(otherQuery1, otherQuery2))
var query = or(
// matched with id 101
and(equal("lastName", "Day"), equal("managerId", "102")),
// matched with id 100, 103
and(
equal("hireDate", "17"),
greaterThan("salary", "1800")
)
);
var resultSet = query.matches(indexView);
assertThat(resultSet).containsExactly("100", "101", "103");
}
}