我正在移動我的項目中的allong,來到處理文件內容的十字路口。我已成功創建了一個具有一些分類字段的工作索引,但我知道希望將關鍵字搜索應用於文件內容。我的問題是我不確定是否傳遞lucene讀者會轉換爲API索引整個文件內容。我在網上搜索了一些東西,發現一些IFilter需要的建議是真的嗎?這似乎有點複雜。無論如何,我的代碼索引文件內容是低於和不工作(如果讀者通過它失敗)。理想情況下,我希望能夠處理doc和docx文件。任何幫助深表感謝。IFilter是使用Lucene.NET索引全文文檔所必需的
我的代碼創建一個讀者
public void setFileText()
{
var FD = new System.Windows.Forms.OpenFileDialog();
StreamReader reader;
if (FD.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string fileToOpen = FD.FileName;
reader = new StreamReader(fileToOpen);
}
else
{
reader = null;
}
this.FileText = reader;
}
}
我的代碼本身的文件添加到索引
private static void _addToLuceneIndex(MATS_Doc Data, IndexWriter writer)
{
// remove older index entry
// Query searchQuery = new TermQuery(new Term("Id", Data.Id.ToString()));
// writer.DeleteDocuments(searchQuery);
// add new index entry
Document doc = new Document();
// add lucene fields mapped to db fields
doc.Add(new Field("Id", Data.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
if (!string.IsNullOrEmpty(Data.Title))
doc.Add(new Field("Title", Data.Title, Field.Store.YES, Field.Index.NOT_ANALYZED));
if (!string.IsNullOrEmpty(Data.Plant))
doc.Add(new Field("Plant", Data.Plant, Field.Store.YES, Field.Index.NOT_ANALYZED));
if (!string.IsNullOrEmpty(Data.Containment))
doc.Add(new Field("Containment", Data.Containment, Field.Store.YES, Field.Index.NOT_ANALYZED));
if (!string.IsNullOrEmpty(Data.Part))
doc.Add(new Field("Part", Data.Part, Field.Store.YES, Field.Index.NOT_ANALYZED));
if (!string.IsNullOrEmpty(Data.Operation))
doc.Add(new Field("Operation", Data.Operation, Field.Store.YES, Field.Index.NOT_ANALYZED));
if (!string.IsNullOrEmpty(Data.Geometry))
doc.Add(new Field("Geometry", Data.Geometry, Field.Store.YES, Field.Index.NOT_ANALYZED));
if (Data.FileText != null)
doc.Add(new Field("Text", Data.FileText));
// add entry to index
writer.AddDocument(doc);
}
感謝您的信息,這有助於! – TheCodeNovice 2013-03-05 15:25:53