Skip to content

Commit

Permalink
gh-13340: Allow adding a parent field to an index with no fields (#13341
Browse files Browse the repository at this point in the history
) (#13483)
  • Loading branch information
msokolov authored Jun 13, 2024
1 parent c45616a commit bae68cc
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 @@ -1125,6 +1125,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 @@ -4949,7 +4949,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 @@ -5057,4 +5059,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 bae68cc

Please sign in to comment.