代码如下:
Term term = new Term("id", "17819"); IndexWriter writer = new IndexWriter("D:/index/", new ChineseAnalyzer(), false); Document doc = new Document(); doc.Add(new Field("id", "17819", Field.Store.YES, Field.Index.UN_TOKENIZED));//此处应是Field.Index.UN_TOKENIZED而不是 Field.Index.TOKENIZED,如果是后者,执行UpdateDocument方法会添加一条新索引数据 doc.Add(new Field("title", "用户控制123232", Field.Store.YES, Field.Index.TOKENIZED)); doc.Add(new Field("summary", "23用户控制232221", Field.Store.YES, Field.Index.TOKENIZED)); writer.UpdateDocument(term, doc); writer.Close();