我注意到indexwriter在打开时会删除索引文件夹中的所有文件。当我跟踪代码时,我看到在indexwriter.close()事件之后没有提交段文件。
这是一个错误吗?或者我需要配置indexwriter?(Lucene 3.03)
public IndexWriter iw_global { get; set; }
...
RAMDirectory idx = new RAMDirectory();
IndexWriter iw = new IndexWriter(idx, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), true, IndexWriter.MaxFieldLength.UNLIMITED);
iw.UseCompoundFile = true;
List<Document> docs = new List<Document>();
#region Index Ekle
foreach (var link in linkList)
{
Document docx = new Document();
//docx.Add(new NumericField("id", Field.Store.YES, true).SetLongValue(link.id));
docx.Add(new Field("id", link.id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
//docx.Add(new NumericField("index_tarih", Field.Store.YES, true).SetLongValue(link.index_tarih.Ticks));
docx.Add(new Field("index_tarih", link.index_tarih.Ticks.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
iw.AddDocument(docx);
}
iw.Commit();
this.iw_global.AddIndexesNoOptimize(idx);
.......
iw.Dispose();
idx.Dispose();
打开iw_global,
private void MasterIndexOpen()
{
DirectoryInfo dirAktif = new DirectoryInfo(Path.Combine(ConfigFile.ConfigsPaths["MasterIndex"], this.courrent_date.ToString("yyyy.MM.dd")));
if (!dirAktif.Exists)
dirAktif.Create();
FileInfo LockFile = new FileInfo(Path.Combine(dirAktif.FullName,"write.lock"));
if (LockFile.Exists)
LockFile.Delete();
Lucene.Net.Store.FSDirectory lcneFolder = Lucene.Net.Store.FSDirectory.Open(dirAktif);
FileInfo fiAktifYes = new FileInfo(string.Format("{0}\\Yes.txt", dirAktif.FullName));
this.iw_global = new IndexWriter(lcneFolder, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), !fiAktifYes.Exists, IndexWriter.MaxFieldLength.UNLIMITED);
this.iw_global.Commit();
this.iw_global.UseCompoundFile = true;
if (!fiAktifYes.Exists)
fiAktifYes.Create();
}