上一篇讲了如何在lucene.net 中建索引目录,建立索引,以及文档。本次是主要是提供一个新增doc的方法public void makeNewsSearchDocument(object sender, System.EventArgs e) { Analyzer analyzer = new StandardAnalyzer(); Directory directory = FSDirectory.GetDirectory(@"c:/tmp/testindex",false);// 对同一索引目录这里参数必须是false IndexWriter iwriter = new IndexWriter(directory, analyzer,false);//索引的写入同样也是false Document doc = new Document(); doc.Add(Field.Keyword("nid","3")); doc.Add(Field.Text("title","我是一个人2")); doc.Add(Field.UnStored("content","请输入你是一个好人的理由2")); doc.Add(Field.Keyword("addtime",mydate)); doc.Add(Field.UnStored("other", "nothing2")); String newsUrl = "/news/viewhtml/test2.htm"; doc.Add(Field.UnIndexed("visiturl", newsUrl)); iwriter.AddDocument(doc); iwriter.Close(); }