コード例 #1
0
ファイル: HumorLucene.cs プロジェクト: besile/jita
 //临时数据代替表单提交
 /// <summary>
 /// 单个创建索引
 /// </summary>
 /// <param name="humor"></param>
 public static void InsertToIndex(T_Humor_HumorInfo humor)
 {
     LuceneManage.Excute(lucene =>
     {
         Document document = new Document();
         document.Add(new Field("id", humor.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
         document.Add(new Field("title", humor.HumorTitle, Field.Store.YES, Field.Index.ANALYZED,
             Field.TermVector.WITH_POSITIONS_OFFSETS));
         document.Add(new Field("content", humor.HumorContent, Field.Store.YES, Field.Index.ANALYZED,
             Field.TermVector.WITH_POSITIONS_OFFSETS));
         lucene.AddDocument(document);
         lucene.Commit();
     });
 }
コード例 #2
0
ファイル: HumorLucene.cs プロジェクト: besile/jita
 public static bool UpdateIndex(T_Humor_HumorInfo humor)
 {
     return LuceneManage.Excute<bool>(lucene =>
     {
         Term term = new Term("id", humor.Id.ToString());
         lucene.DeleteDocuments(term);
         var success = lucene.HasDeletions();
         if (success == false)
         {
             return false;
         }
         Document document = new Document();
         document.Add(new Field("id", humor.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
         document.Add(new Field("title", humor.HumorTitle, Field.Store.YES, Field.Index.ANALYZED,
             Field.TermVector.WITH_POSITIONS_OFFSETS));
         document.Add(new Field("content", humor.HumorContent, Field.Store.YES, Field.Index.ANALYZED,
             Field.TermVector.WITH_POSITIONS_OFFSETS));
         lucene.AddDocument(document);
         lucene.Commit();
         return true;
     });
 }