@@ -1134,4 +1134,167 @@ public void testOrQueriesWithArrayMembership() {
11341134 "doc4" ,
11351135 "doc6" );
11361136 }
1137+
1138+ @ Test
1139+ public void multipleInOps () {
1140+ Map <String , Map <String , Object >> testDocs =
1141+ map (
1142+ "doc1" , map ("a" , 1 , "b" , 0 ),
1143+ "doc2" , map ("b" , 1 ),
1144+ "doc3" , map ("a" , 3 , "b" , 2 ),
1145+ "doc4" , map ("a" , 1 , "b" , 3 ),
1146+ "doc5" , map ("a" , 1 ),
1147+ "doc6" , map ("a" , 2 ));
1148+ CollectionReference collection = testCollectionWithDocs (testDocs );
1149+
1150+ // Two IN operations on different fields with disjunction.
1151+ Query query1 =
1152+ collection
1153+ .where (Filter .or (Filter .inArray ("a" , asList (2 , 3 )), Filter .inArray ("b" , asList (0 , 2 ))))
1154+ .orderBy ("a" );
1155+ checkOnlineAndOfflineResultsMatch (query1 , "doc1" , "doc6" , "doc3" );
1156+
1157+ // Two IN operations on different fields with conjunction.
1158+ Query query2 =
1159+ collection
1160+ .where (Filter .and (Filter .inArray ("a" , asList (2 , 3 )), Filter .inArray ("b" , asList (0 , 2 ))))
1161+ .orderBy ("a" );
1162+ checkOnlineAndOfflineResultsMatch (query2 , "doc3" );
1163+
1164+ // Two IN operations on the same field.
1165+ // a IN [1,2,3] && a IN [0,1,4] should result in "a==1".
1166+ Query query3 =
1167+ collection .where (
1168+ Filter .and (Filter .inArray ("a" , asList (1 , 2 , 3 )), Filter .inArray ("a" , asList (0 , 1 , 4 ))));
1169+ checkOnlineAndOfflineResultsMatch (query3 , "doc1" , "doc4" , "doc5" );
1170+
1171+ // a IN [2,3] && a IN [0,1,4] is never true and so the result should be an empty set.
1172+ Query query4 =
1173+ collection .where (
1174+ Filter .and (Filter .inArray ("a" , asList (2 , 3 )), Filter .inArray ("a" , asList (0 , 1 , 4 ))));
1175+ checkOnlineAndOfflineResultsMatch (query4 );
1176+
1177+ // a IN [0,3] || a IN [0,2] should union them (similar to: a IN [0,2,3]).
1178+ Query query5 =
1179+ collection .where (
1180+ Filter .or (Filter .inArray ("a" , asList (0 , 3 )), Filter .inArray ("a" , asList (0 , 2 ))));
1181+ checkOnlineAndOfflineResultsMatch (query5 , "doc3" , "doc6" );
1182+
1183+ // Nested composite filter on the same field.
1184+ Query query6 =
1185+ collection .where (
1186+ Filter .and (
1187+ Filter .inArray ("a" , asList (1 , 3 )),
1188+ Filter .or (
1189+ Filter .inArray ("a" , asList (0 , 2 )),
1190+ Filter .and (
1191+ Filter .greaterThanOrEqualTo ("b" , 1 ), Filter .inArray ("a" , asList (1 , 3 ))))));
1192+ checkOnlineAndOfflineResultsMatch (query6 , "doc3" , "doc4" );
1193+
1194+ // Nested composite filter on different fields.
1195+ Query query7 =
1196+ collection .where (
1197+ Filter .and (
1198+ Filter .inArray ("b" , asList (0 , 3 )),
1199+ Filter .or (
1200+ Filter .inArray ("b" , asList (1 )),
1201+ Filter .and (
1202+ Filter .inArray ("b" , asList (2 , 3 )), Filter .inArray ("a" , asList (1 , 3 ))))));
1203+ checkOnlineAndOfflineResultsMatch (query7 , "doc4" );
1204+ }
1205+
1206+ @ Test
1207+ public void useInWithArrayContainsAny () {
1208+ Map <String , Map <String , Object >> testDocs =
1209+ map (
1210+ "doc1" , map ("a" , 1 , "b" , asList (0 )),
1211+ "doc2" , map ("b" , asList (1 )),
1212+ "doc3" , map ("a" , 3 , "b" , asList (2 , 7 ), "c" , 10 ),
1213+ "doc4" , map ("a" , 1 , "b" , asList (3 , 7 )),
1214+ "doc5" , map ("a" , 1 ),
1215+ "doc6" , map ("a" , 2 , "c" , 20 ));
1216+ CollectionReference collection = testCollectionWithDocs (testDocs );
1217+
1218+ Query query1 =
1219+ collection .where (
1220+ Filter .or (
1221+ Filter .inArray ("a" , asList (2 , 3 )), Filter .arrayContainsAny ("b" , asList (0 , 7 ))));
1222+ checkOnlineAndOfflineResultsMatch (query1 , "doc1" , "doc3" , "doc4" , "doc6" );
1223+
1224+ Query query2 =
1225+ collection .where (
1226+ Filter .and (
1227+ Filter .inArray ("a" , asList (2 , 3 )), Filter .arrayContainsAny ("b" , asList (0 , 7 ))));
1228+ checkOnlineAndOfflineResultsMatch (query2 , "doc3" );
1229+
1230+ Query query3 =
1231+ collection .where (
1232+ Filter .or (
1233+ Filter .and (Filter .inArray ("a" , asList (2 , 3 )), Filter .equalTo ("c" , 10 )),
1234+ Filter .arrayContainsAny ("b" , asList (0 , 7 ))));
1235+ checkOnlineAndOfflineResultsMatch (query3 , "doc1" , "doc3" , "doc4" );
1236+
1237+ Query query4 =
1238+ collection .where (
1239+ Filter .and (
1240+ Filter .inArray ("a" , asList (2 , 3 )),
1241+ Filter .or (Filter .arrayContainsAny ("b" , asList (0 , 7 )), Filter .equalTo ("c" , 20 ))));
1242+ checkOnlineAndOfflineResultsMatch (query4 , "doc3" , "doc6" );
1243+ }
1244+
1245+ @ Test
1246+ public void useInWithArrayContains () {
1247+ Map <String , Map <String , Object >> testDocs =
1248+ map (
1249+ "doc1" , map ("a" , 1 , "b" , asList (0 )),
1250+ "doc2" , map ("b" , asList (1 )),
1251+ "doc3" , map ("a" , 3 , "b" , asList (2 , 7 )),
1252+ "doc4" , map ("a" , 1 , "b" , asList (3 , 7 )),
1253+ "doc5" , map ("a" , 1 ),
1254+ "doc6" , map ("a" , 2 ));
1255+ CollectionReference collection = testCollectionWithDocs (testDocs );
1256+
1257+ Query query1 =
1258+ collection .where (
1259+ Filter .or (Filter .inArray ("a" , asList (2 , 3 )), Filter .arrayContains ("b" , 3 )));
1260+ checkOnlineAndOfflineResultsMatch (query1 , "doc3" , "doc4" , "doc6" );
1261+
1262+ Query query2 =
1263+ collection .where (
1264+ Filter .and (Filter .inArray ("a" , asList (2 , 3 )), Filter .arrayContains ("b" , 7 )));
1265+ checkOnlineAndOfflineResultsMatch (query2 , "doc3" );
1266+
1267+ Query query3 =
1268+ collection .where (
1269+ Filter .or (
1270+ Filter .inArray ("a" , asList (2 , 3 )),
1271+ Filter .and (Filter .arrayContains ("b" , 3 ), Filter .equalTo ("a" , 1 ))));
1272+ checkOnlineAndOfflineResultsMatch (query3 , "doc3" , "doc4" , "doc6" );
1273+
1274+ Query query4 =
1275+ collection .where (
1276+ Filter .and (
1277+ Filter .inArray ("a" , asList (2 , 3 )),
1278+ Filter .or (Filter .arrayContains ("b" , 7 ), Filter .equalTo ("a" , 1 ))));
1279+ checkOnlineAndOfflineResultsMatch (query4 , "doc3" );
1280+ }
1281+
1282+ @ Test
1283+ public void orderByEquality () {
1284+ Map <String , Map <String , Object >> testDocs =
1285+ map (
1286+ "doc1" , map ("a" , 1 , "b" , asList (0 )),
1287+ "doc2" , map ("b" , asList (1 )),
1288+ "doc3" , map ("a" , 3 , "b" , asList (2 , 7 ), "c" , 10 ),
1289+ "doc4" , map ("a" , 1 , "b" , asList (3 , 7 )),
1290+ "doc5" , map ("a" , 1 ),
1291+ "doc6" , map ("a" , 2 , "c" , 20 ));
1292+ CollectionReference collection = testCollectionWithDocs (testDocs );
1293+
1294+ Query query1 = collection .where (Filter .equalTo ("a" , 1 )).orderBy ("a" );
1295+ checkOnlineAndOfflineResultsMatch (query1 , "doc1" , "doc4" , "doc5" );
1296+
1297+ Query query2 = collection .where (Filter .inArray ("a" , asList (2 , 3 ))).orderBy ("a" );
1298+ checkOnlineAndOfflineResultsMatch (query2 , "doc6" , "doc3" );
1299+ }
11371300}
0 commit comments