Skip to content

Commit

Permalink
[release-2.13] fix: query mismatch with non-intersecting OR and neste…
Browse files Browse the repository at this point in the history
…d AND condition (#5455)

This is an automated cherry-pick of #5452

/assign guqing

```release-note
None
```
  • Loading branch information
halo-dev-bot authored Mar 6, 2024
1 parent 95c9188 commit 9473261
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 0 additions & 2 deletions api/src/main/java/run/halo/app/extension/index/query/And.java
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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");
}
}

0 comments on commit 9473261

Please sign in to comment.