msokolov commented on code in PR #12829:
URL: https://github.com/apache/lucene/pull/12829#discussion_r1401297534


##########
lucene/core/src/test/org/apache/lucene/index/TestIndexSorting.java:
##########
@@ -3173,4 +3173,184 @@ public void 
testSortDocsAndFreqsAndPositionsAndOffsets() throws IOException {
     reader.close();
     dir.close();
   }
+
+  public void testBlockIsMissingParentField() throws IOException {
+    try (Directory dir = newDirectory()) {
+      IndexWriterConfig iwc = new IndexWriterConfig(new 
MockAnalyzer(random()));
+      String parentField = "parent";
+      Sort indexSort = new Sort(parentField, new SortField("foo", 
SortField.Type.INT));
+      iwc.setIndexSort(indexSort);
+      try (IndexWriter writer = new IndexWriter(dir, iwc)) {
+        List<Runnable> runnabels =
+            Arrays.asList(
+                () -> {
+                  IllegalArgumentException ex =
+                      expectThrows(
+                          IllegalArgumentException.class,
+                          () -> {
+                            writer.addDocuments(Arrays.asList(new Document(), 
new Document()));
+                          });
+                  assertEquals(
+                      "the last document in the block must contain a numeric 
doc values field named: parent",
+                      ex.getMessage());
+                },
+                () -> {
+                  IllegalArgumentException ex =
+                      expectThrows(
+                          IllegalArgumentException.class,
+                          () -> {
+                            Document doc = new Document();
+                            doc.add(new NumericDocValuesField("parent", 0));
+                            writer.addDocuments(Arrays.asList(doc, new 
Document()));
+                          });
+                  assertEquals(
+                      "only the last document in the block must contain a 
numeric doc values field named: parent",
+                      ex.getMessage());
+                },
+                () -> {
+                  IllegalArgumentException ex =
+                      expectThrows(
+                          IllegalArgumentException.class,
+                          () -> {
+                            writer.addDocuments(Arrays.asList(new Document()));
+                          });
+                  assertEquals(
+                      "the last document in the block must contain a numeric 
doc values field named: parent",
+                      ex.getMessage());
+                });
+        Collections.shuffle(runnabels, random());
+        for (Runnable runnable : runnabels) {
+          runnable.run();
+        }
+      }
+    }
+  }
+
+  public void testIndexWithSortIsCongruent() throws IOException {
+    try (Directory dir = newDirectory()) {
+      IndexWriterConfig iwc = new IndexWriterConfig(new 
MockAnalyzer(random()));
+      String parentField = "parent";
+      Sort indexSort = new Sort(parentField, new SortField("foo", 
SortField.Type.INT));
+      iwc.setIndexSort(indexSort);
+      try (IndexWriter writer = new IndexWriter(dir, iwc)) {
+        Document child1 = new Document();
+        child1.add(new StringField("id", Integer.toString(1), Store.YES));
+        Document child2 = new Document();
+        child2.add(new StringField("id", Integer.toString(1), Store.YES));
+        Document parent = new Document();
+        parent.add(new StringField("id", Integer.toString(1), Store.YES));
+        parent.add(new NumericDocValuesField(parentField, 0));

Review Comment:
   Is the value `0` significant in any way?



##########
lucene/core/src/test/org/apache/lucene/index/TestIndexSorting.java:
##########
@@ -3173,4 +3173,184 @@ public void 
testSortDocsAndFreqsAndPositionsAndOffsets() throws IOException {
     reader.close();
     dir.close();
   }
+
+  public void testBlockIsMissingParentField() throws IOException {
+    try (Directory dir = newDirectory()) {
+      IndexWriterConfig iwc = new IndexWriterConfig(new 
MockAnalyzer(random()));
+      String parentField = "parent";
+      Sort indexSort = new Sort(parentField, new SortField("foo", 
SortField.Type.INT));
+      iwc.setIndexSort(indexSort);
+      try (IndexWriter writer = new IndexWriter(dir, iwc)) {
+        List<Runnable> runnabels =
+            Arrays.asList(
+                () -> {
+                  IllegalArgumentException ex =
+                      expectThrows(
+                          IllegalArgumentException.class,
+                          () -> {
+                            writer.addDocuments(Arrays.asList(new Document(), 
new Document()));
+                          });
+                  assertEquals(
+                      "the last document in the block must contain a numeric 
doc values field named: parent",
+                      ex.getMessage());
+                },
+                () -> {
+                  IllegalArgumentException ex =
+                      expectThrows(
+                          IllegalArgumentException.class,
+                          () -> {
+                            Document doc = new Document();
+                            doc.add(new NumericDocValuesField("parent", 0));
+                            writer.addDocuments(Arrays.asList(doc, new 
Document()));
+                          });
+                  assertEquals(
+                      "only the last document in the block must contain a 
numeric doc values field named: parent",

Review Comment:
   I think this will prevent us from handling multiple levels of nested child 
documents -- with a sort. I guess that would require multiple bitsets so you 
can do different kinds of joins. Seems kind of involved, but I think it is 
possible today?



##########
lucene/core/src/test/org/apache/lucene/index/TestIndexSorting.java:
##########
@@ -3173,4 +3173,184 @@ public void 
testSortDocsAndFreqsAndPositionsAndOffsets() throws IOException {
     reader.close();
     dir.close();
   }
+
+  public void testBlockIsMissingParentField() throws IOException {
+    try (Directory dir = newDirectory()) {
+      IndexWriterConfig iwc = new IndexWriterConfig(new 
MockAnalyzer(random()));
+      String parentField = "parent";
+      Sort indexSort = new Sort(parentField, new SortField("foo", 
SortField.Type.INT));
+      iwc.setIndexSort(indexSort);
+      try (IndexWriter writer = new IndexWriter(dir, iwc)) {
+        List<Runnable> runnabels =
+            Arrays.asList(
+                () -> {
+                  IllegalArgumentException ex =
+                      expectThrows(
+                          IllegalArgumentException.class,
+                          () -> {
+                            writer.addDocuments(Arrays.asList(new Document(), 
new Document()));
+                          });
+                  assertEquals(
+                      "the last document in the block must contain a numeric 
doc values field named: parent",
+                      ex.getMessage());
+                },
+                () -> {
+                  IllegalArgumentException ex =
+                      expectThrows(
+                          IllegalArgumentException.class,
+                          () -> {
+                            Document doc = new Document();
+                            doc.add(new NumericDocValuesField("parent", 0));
+                            writer.addDocuments(Arrays.asList(doc, new 
Document()));
+                          });
+                  assertEquals(
+                      "only the last document in the block must contain a 
numeric doc values field named: parent",
+                      ex.getMessage());
+                },
+                () -> {
+                  IllegalArgumentException ex =
+                      expectThrows(
+                          IllegalArgumentException.class,
+                          () -> {
+                            writer.addDocuments(Arrays.asList(new Document()));
+                          });
+                  assertEquals(
+                      "the last document in the block must contain a numeric 
doc values field named: parent",
+                      ex.getMessage());
+                });
+        Collections.shuffle(runnabels, random());
+        for (Runnable runnable : runnabels) {
+          runnable.run();
+        }
+      }
+    }
+  }
+
+  public void testIndexWithSortIsCongruent() throws IOException {
+    try (Directory dir = newDirectory()) {
+      IndexWriterConfig iwc = new IndexWriterConfig(new 
MockAnalyzer(random()));
+      String parentField = "parent";
+      Sort indexSort = new Sort(parentField, new SortField("foo", 
SortField.Type.INT));
+      iwc.setIndexSort(indexSort);
+      try (IndexWriter writer = new IndexWriter(dir, iwc)) {
+        Document child1 = new Document();
+        child1.add(new StringField("id", Integer.toString(1), Store.YES));
+        Document child2 = new Document();
+        child2.add(new StringField("id", Integer.toString(1), Store.YES));
+        Document parent = new Document();
+        parent.add(new StringField("id", Integer.toString(1), Store.YES));
+        parent.add(new NumericDocValuesField(parentField, 0));

Review Comment:
   I wonder if we could use the value to indicate different parent/child 
relations?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to