private void CreateIndex(EditViewArticle article) { //using (var analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.LuceneVersion.LUCENE_48)) //{ var options = new Lucene.Net.Index.IndexWriterConfig(Lucene.Net.Util.LuceneVersion.LUCENE_48, null) { OpenMode = Lucene.Net.Index.OpenMode.CREATE }; //using (var indexWriter = new Lucene.Net.Index.IndexWriter(_directory, analyzer, Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED)) using (var indexWriter = new Lucene.Net.Index.IndexWriter(_directory, options)) { var document = new Lucene.Net.Documents.Document { new Lucene.Net.Documents.TextField("Id", article.Id.ToString(), Lucene.Net.Documents.Field.Store.YES), new Lucene.Net.Documents.TextField("Title", article.Title, Lucene.Net.Documents.Field.Store.YES), // HTML文本 // old版本//document.Add(new Lucene.Net.Documents.Field("Contents", article.Contents, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.ANALYZED)); //document.Add(new Lucene.Net.Documents.TextField("Contents", article.Contents, Lucene.Net.Documents.Field.Store.YES)); // 纯文本 new Lucene.Net.Documents.TextField("TContents", article.Summary, Lucene.Net.Documents.Field.Store.YES), new Lucene.Net.Documents.TextField("CreateTime", article.CreateTime.ToString(), Lucene.Net.Documents.Field.Store.YES) }; indexWriter.AddDocument(document, this.CreateAnalyzer()); indexWriter.Commit(); } //} }
public IActionResult Contact() { ViewData["Message"] = "Your contact page."; LuceneHelper lHelper = new LuceneHelper(_hostingEnvironment.WebRootPath); var eA = new EditViewArticle() { Id = 1007, Title = "吃神农放心肉 享健康人生——2018“神农杯”高尔夫邀请赛圆满结束", Summary = "5月6日,清风和畅 天高云阔 在绿草如茵、风景如画的 昆明玉龙湾高尔夫球场 2018神农杯高尔夫邀请赛华丽开杆 一百多位神农合作伙伴参加了比赛", CreateTime = DateTime.Now }; lHelper.AddIndex(eA); return(View()); }
/// <summary> /// 添加索引 /// </summary> /// <param name="article">文章信息</param> public void AddIndex(EditViewArticle article) { //DeleteIndexById(article.Id); CreateIndex(article); }