作者:全程解密_785 | 来源:互联网 | 2023-05-27 18:02
1> femtoRgon..:
您不需要在每次迭代时将字段添加到doc.添加字段一次后,您需要做的就是更改字段值,然后将更改的文档写入索引,如下所示:
Document doc = new Document();
Field field1 = new TextField("field1", field1Value, Field.Store.YES);
doc.add(field1);
Field field2 = new StringField("field2", field2Value,Field.Store.YES);
doc.add(field2);
while ((line = br.readLine()) != null) {
field1.setStringValue("field1Value");
field2.setStringValue("field2Value");
writer.addDocument(doc);
}