Skip to content

Commit

Permalink
apachegh-13340: Allow adding a parent field to an index with no fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Sokolov committed May 2, 2024
1 parent c3b0e05 commit c64a1a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,7 @@ public IndexWriter(Directory d, IndexWriterConfig conf) throws IOException {
globalFieldNumberMap = getFieldNumberMap();
if (create == false
&& conf.getParentField() != null
&& globalFieldNumberMap.getFieldNames().isEmpty() == false
&& globalFieldNumberMap.getFieldNames().contains(conf.getParentField()) == false) {
throw new IllegalArgumentException(
"can't add a parent field to an already existing index without a parent field");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4851,7 +4851,9 @@ public void testParentFieldExistingIndex() throws IOException {
try (Directory dir = newDirectory()) {
IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
try (IndexWriter writer = new IndexWriter(dir, iwc)) {
writer.addDocument(new Document());
Document d = new Document();
d.add(new TextField("f", "a", Field.Store.NO));
writer.addDocument(d);
}
IllegalArgumentException iae =
expectThrows(
Expand Down Expand Up @@ -4959,4 +4961,19 @@ public void testParentFieldIsAlreadyUsed() throws IOException {
iae.getMessage());
}
}

public void testParentFieldEmptyIndex() throws IOException {
try (Directory dir = newMockDirectory()) {
IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
iwc.setParentField("parent");
try (IndexWriter writer = new IndexWriter(dir, iwc)) {
writer.commit();
}
IndexWriterConfig iwc2 = new IndexWriterConfig(new MockAnalyzer(random()));
iwc2.setParentField("parent");
try (IndexWriter writer = new IndexWriter(dir, iwc2)) {
writer.commit();
}
}
}
}

0 comments on commit c64a1a3

Please sign in to comment.