//根据id添加或者修改索引 public void InsertOrUpdate <T>(T model) { var doc = LuceneTool.CreateDoc(model); var term = new Term("Id", doc.Get("Id")); LuceneTool.GetIndexWriter(indexName).UpdateDocument(term, doc); }
//批量添加索引 public void InsertMany <T>(IEnumerable <T> list) { foreach (var item in list) { var doc = LuceneTool.CreateDoc(item); LuceneTool.GetIndexWriter(indexName).AddDocument(doc); } }
//批量根据id添加或者修改索引 public void InsertOrUpdateMany <T>(IEnumerable <T> list) { foreach (var item in list) { var doc = LuceneTool.CreateDoc(item); var term = new Term("Id", doc.Get("Id")); LuceneTool.GetIndexWriter(indexName).UpdateDocument(term, doc); } }
//添加索引 public void Insert <T>(T model) { var doc = LuceneTool.CreateDoc(model); LuceneTool.GetIndexWriter(indexName).AddDocument(doc); }