Exemple #1
0
 public ActionResult Edit(SampleData data)
 {
     if (data.Id == 0)
     {
         ViewData["msg"] = "Id不能为空";
     }
     else if (string.IsNullOrEmpty(data.Name))
     {
         ViewData["msg"] = "Name不能为空";
     }
     else if (string.IsNullOrEmpty(data.Description))
     {
         ViewData["msg"] = "Description不能为空";
     }
     else
     {
         if (GoLucene.Search(data.Id.ToString(), "Id").Any())
         {
             ViewData["msg"] = "Id已存在";
         }
         else
         {
             IndexQueue.GetInstance().AddQueue(new Data { SampleData = data, OptionType = IndexOptionType.Add });
         }
     }
     return View();
 }
Exemple #2
0
        /// <summary>
        /// 添加单个索引数据
        /// </summary>
        /// <param name="data"></param>
        /// <param name="writer"></param>
        private static void AddToLuceneIndex(SampleData data, IndexWriter writer)
        {
            var searchQuery = new TermQuery(new Term("Id", data.Id.ToString()));
            writer.DeleteDocuments(searchQuery);

            var doc = new Lucene.Net.Documents.Document();
            doc.Add(new Field("Id", data.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("Name", data.Name, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("Description", data.Description, Field.Store.YES, Field.Index.ANALYZED));

            writer.AddDocument(doc);
        }
Exemple #3
0
 public static void UpdateLuceneIndex(SampleData data)
 {
     UpdateLuceneIndex(new[] { data });
 }