|
2 | 2 |
|
3 | 3 | import org.dizitart.no2.Nitrite; |
4 | 4 | import org.dizitart.no2.collection.Document; |
| 5 | +import org.dizitart.no2.collection.DocumentCursor; |
5 | 6 | import org.dizitart.no2.collection.NitriteCollection; |
| 7 | +import org.dizitart.no2.filters.Filter; |
6 | 8 | import org.dizitart.no2.filters.FluentFilter; |
7 | 9 | import org.dizitart.no2.index.IndexOptions; |
8 | 10 | import org.dizitart.no2.index.IndexType; |
9 | 11 | import org.junit.After; |
10 | 12 | import org.junit.Before; |
11 | 13 | import org.junit.Test; |
12 | 14 |
|
| 15 | +import java.util.ArrayList; |
| 16 | +import java.util.Iterator; |
| 17 | +import java.util.List; |
| 18 | + |
13 | 19 | import static org.junit.Assert.assertEquals; |
14 | 20 |
|
15 | 21 | public class IssueTest { |
@@ -47,4 +53,32 @@ public void testOriginalIssue() { |
47 | 53 | assertEquals(1, collection.find(FluentFilter.where("value").lte(42L)).size()); |
48 | 54 | assertEquals(1, collection.find(FluentFilter.where("value").gte(42L)).size()); |
49 | 55 | } |
| 56 | + |
| 57 | + @Test |
| 58 | + public void testMultipleIndexesOrFilterDuplicates() { |
| 59 | + NitriteCollection items = db.getCollection("items"); |
| 60 | + items.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "field_a"); |
| 61 | + items.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "field_b"); |
| 62 | + |
| 63 | + Document doc = Document.createDocument(); |
| 64 | + doc.put("field_a", "A"); |
| 65 | + doc.put("field_b", "B"); |
| 66 | + items.insert(doc); |
| 67 | + |
| 68 | + Filter aFilter = FluentFilter.where("field_a").eq("A"); |
| 69 | + Filter bFilter = FluentFilter.where("field_b").eq("B"); |
| 70 | + |
| 71 | + Filter orFilter = Filter.or(aFilter, bFilter); |
| 72 | + |
| 73 | + DocumentCursor cursor = items.find(orFilter); |
| 74 | + Iterator<Document> docIter = cursor.iterator(); |
| 75 | + |
| 76 | + List<Long> matches = new ArrayList<>(); |
| 77 | + while (docIter.hasNext()) { |
| 78 | + Document match = docIter.next(); |
| 79 | + long id = match.getId().getIdValue(); |
| 80 | + matches.add(id); |
| 81 | + } |
| 82 | + assertEquals("Single document must yield single match", 1, matches.size()); |
| 83 | + } |
50 | 84 | } |
0 commit comments