我正在使用lucene.net来索引我的pdf文件。它需要大约40分钟来索引15000个pdf文件,并且随着我的文件夹中pdf文件数量的增加,索引时间也会增加。
- 如何提高lucene.net的索引速度?
- 是否有其他具有快速索引性能的索引服务?
我正在使用最新版本的lucene.net索引(Lucene.net 3.0.3)。
以下是我的索引代码。
public void refreshIndexes()
{
// Create Index Writer
string strIndexDir = @"E:\LuceneTest\index";
IndexWriter writer = new IndexWriter(Lucene.Net.Store.FSDirectory.Open(new System.IO.DirectoryInfo(strIndexDir)), new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), true, IndexWriter.MaxFieldLength.UNLIMITED);
// Find all files in root folder create index on them
List<string> lstFiles = searchFiles(@"E:\LuceneTest\PDFs");
foreach (string strFile in lstFiles)
{
Document doc = new Document();
string FileName = System.IO.Path.GetFileNameWithoutExtension(strFile);
string Text = ExtractTextFromPdf(strFile);
string Path = strFile;
string ModifiedDate = Convert.ToString(File.GetLastWriteTime(strFile));
string DocumentType = string.Empty;
string Vault = string.Empty;
string headerText = Text.Substring(0, Text.Length < 150 ? Text.Length : 150);
foreach (var docs in ltDocumentTypes)
{
if (headerText.ToUpper().Contains(docs.searchText.ToUpper()))
{
DocumentType = docs.DocumentType;
Vault = docs.VaultName; ;
}
}
if (string.IsNullOrEmpty(DocumentType))
{
DocumentType = "Default";
Vault = "Default";
}
doc.Add(new Field("filename", FileName, Field.Store.YES, Field.Index.ANALYZED));
doc.Add(new Field("text", Text, Field.Store.YES, Field.Index.ANALYZED));
doc.Add(new Field("path", Path, Field.Store.YES, Field.Index.NOT_ANALYZED));
doc.Add(new Field("modifieddate", ModifiedDate, Field.Store.YES, Field.Index.ANALYZED));
doc.Add(new Field("documenttype", DocumentType, Field.Store.YES, Field.Index.ANALYZED));
doc.Add(new Field("vault", Vault, Field.Store.YES, Field.Index.ANALYZED));
writer.AddDocument(doc);
}
writer.Optimize();
writer.Dispose();
}
writer.Optimize()
吗?writer.Commit()
是不是已经足够了? - sisve