我正在尝试将文档添加到索引中,但是当我尝试运行以下函数时,它会返回numDocs
并1
覆盖前一个文档!难道我做错了什么?我在另一个项目上做了同样的事情,效果很好!
IndexWriter writer;
Directory dir = FSDirectory.open(new File("/home/omid/Desktop/Indexes"));
writer = new IndexWriter(dir, new StandardAnalyzer(Version.LUCENE_34), true, IndexWriter.MaxFieldLength.UNLIMITED);
Document doc = new Document();
doc.add(new NumericField("id", Field.Store.YES, false).setIntValue(writer.numDocs()));
doc.add(new NumericField("day", Field.Store.YES, false).setIntValue(13));
doc.add(new NumericField("month", Field.Store.YES, false).setIntValue(1));
doc.add(new NumericField("year", Field.Store.YES, false).setIntValue(1387));
doc.add(new Field("content", new FileReader(new File(filename)), Field.TermVector.YES));
doc.add(new Field("address", filename,Field.Store.YES, Field.Index.NOT_ANALYZED));
writer.addDocument(doc);
writer.close();
mes = "Indexed Filename: " + filename;
mes = mes + "<BR>Number of docs: " + writer.numDocs();
从 3.4 中的 lucene 3.0 有什么变化吗?或者我正在这样做