From 1e31df007cb084c9dbacea884a86d986d1ccfac4 Mon Sep 17 00:00:00 2001 From: guqing Date: Wed, 6 Mar 2024 15:38:00 +0800 Subject: [PATCH] fix: query mismatch with non-intersecting OR and nested AND condition --- .../halo/app/extension/index/query/And.java | 2 -- .../app/extension/index/query/AndTest.java | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/run/halo/app/extension/index/query/And.java b/api/src/main/java/run/halo/app/extension/index/query/And.java index 4719b881ec..8a80b319f2 100644 --- a/api/src/main/java/run/halo/app/extension/index/query/And.java +++ b/api/src/main/java/run/halo/app/extension/index/query/And.java @@ -25,8 +25,6 @@ public NavigableSet matches(QueryIndexView indexView) { NavigableSet resultSet = null; for (Query query : childQueries) { NavigableSet 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 { diff --git a/api/src/test/java/run/halo/app/extension/index/query/AndTest.java b/api/src/test/java/run/halo/app/extension/index/query/AndTest.java index 5beef4ee0c..d96fcf070e 100644 --- a/api/src/test/java/run/halo/app/extension/index/query/AndTest.java +++ b/api/src/test/java/run/halo/app/extension/index/query/AndTest.java @@ -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"); + } }