而是手动删除和追加来完成这个update操作。
- [WebMethod]
- public int UpdateLuceneDocument(string primaryKey, string id, string name, string info, string categoryName, string propertyName, string module, string passKey)
- {
- int flag = 0;
- try
- {
- dirInfo = Directory.CreateDirectory(this.GetIndexPath(ConfigurationManager.AppSettings[module]));
- directory = LuceneIO.FSDirectory.Open(dirInfo);
- IndexWriter writer = new IndexWriter(directory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), false, IndexWriter.MaxFieldLength.UNLIMITED);
- Document doc = new Document();
- doc.Add(new Field("PrimaryKey", primaryKey, Field.Store.YES, Field.Index.ANALYZED));
- doc.Add(new Field("ID", id, Field.Store.YES, Field.Index.NO));
- doc.Add(new Field("Name", name, Field.Store.YES, Field.Index.ANALYZED));
- doc.Add(new Field("Info", info, Field.Store.YES, Field.Index.ANALYZED));
- doc.Add(new Field("CategoryName", categoryName, Field.Store.YES, Field.Index.ANALYZED));
- doc.Add(new Field("PropertyName", propertyName, Field.Store.YES, Field.Index.ANALYZED));
- QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "PrimaryKey", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29));
- Query query = parser.Parse(primaryKey);
- writer.DeleteDocuments(query);
- writer.Commit();
- writer.AddDocument(doc);
- writer.Optimize();
- writer.Close();
- flag = 1;
- }
- catch (Exception)
- {
- throw;
- }
- return flag;
- }
O