@@ -86,7 +86,11 @@ public void testFindByOrFilterAndFilter() {
8686 )
8787 );
8888
89- assertEquals (3 , cursor .size ());
89+ // With the fix, OR filters no longer return duplicates
90+ // First AND: lastName=ln2 AND firstName!=fn1 → matches doc2 and doc3
91+ // Second AND: firstName=fn3 AND lastName=ln2 → matches doc3
92+ // Union without duplicates: doc2 and doc3 (2 total)
93+ assertEquals (2 , cursor .size ());
9094
9195 FindPlan findPlan = cursor .getFindPlan ();
9296 assertNull (findPlan .getIndexScanFilter ());
@@ -101,11 +105,11 @@ public void testFindByOrFilterAndFilter() {
101105 d .get ("firstName" , String .class ).equals ("fn2" )
102106 && d .get ("lastName" , String .class ).equals ("ln2" )).count ());
103107
104- assertEquals (2 , cursor .toList ().stream ().filter (d ->
108+ assertEquals (1 , cursor .toList ().stream ().filter (d ->
105109 d .get ("firstName" , String .class ).equals ("fn3" )
106110 && d .get ("lastName" , String .class ).equals ("ln2" )).count ());
107111
108- // distinct test
112+ // distinct test - should still return the same results since we're already deduplicating
109113 cursor = collection .find (
110114 or (
111115 and (
@@ -231,11 +235,18 @@ public void testFindByOrFilter() throws ParseException {
231235 )
232236 );
233237
238+ // With the fix, OR filters no longer return duplicates
239+ // Flattened OR conditions:
240+ // 1. lastName=ln2 → doc2, doc3
241+ // 2. firstName!=fn1 → doc2, doc3
242+ // 3. birthDay=2012-07-01 → doc1
243+ // 4. firstName!=fn1 → doc2, doc3 (duplicate)
244+ // Union without duplicates: doc1, doc2, doc3 (3 total)
234245 FindPlan findPlan = cursor .getFindPlan ();
235246 assertEquals (3 , findPlan .getSubPlans ().size ());
236- assertEquals (5 , cursor .size ());
247+ assertEquals (3 , cursor .size ());
237248
238- // distinct
249+ // distinct test - should still return the same results since we're already deduplicating
239250 cursor = collection .find (
240251 or (
241252 or (
0 commit comments