有图有真相

ps:上图可以看到中文分词成功,搜索也命中了;
说明:如果想好好学Lucene建议看Lucene in action 2nd version,另外2.9.2中对以前很多方法已经废弃,旧代码就别看了;
下面是代码:
public static void IndexFile(this IndexWriter writer, IO.FileInfo file) { var watch = new Stopwatch(); var startTime = DateTime.Now; watch.Start(); Console.WriteLine("Indexing {0}", file.Name); writer.AddDocument(file.GetDocument()); watch.Stop(); var timeSpan = DateTime.Now - startTime; Console.WriteLine("Indexing Completed! Cost time {0}[{1}]", timeSpan.ToString("c"), watch.ElapsedMilliseconds); }
public static Document GetDocument(this IO.FileInfo file) { var doc = new Document(); doc.Add(new Field("contents", new IO.StreamReader(file.FullName))); doc.Add(new Field("filename", file.Name, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field("fullpath", file.FullName, Field.Store.YES, Field.Index.NOT_ANALYZED)); return doc; }