public static Journal New() { Journal j = new Journal(); //todo: return j; }
/// <summary> /// BlogThread转换成<see cref="Lucene.Net.Documents.Document"/> /// </summary> /// <param name="journal">日志实体</param> /// <returns>Lucene.Net.Documents.Document</returns> public static Document Convert(Journal journal) { Document doc = new Document(); //索引日志基本信息 doc.Add(new Field(JournalIndexDocument.id, journal.id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(JournalIndexDocument.journalname, journal.journal.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(JournalIndexDocument.abbr, journal.abbr, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(JournalIndexDocument.publisher, journal.publisher.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(JournalIndexDocument.jdescrip, journal.jdescrip, Field.Store.NO, Field.Index.ANALYZED)); doc.Add(new Field(JournalIndexDocument.subcat, journal.subcat , Field.Store.YES, Field.Index.NOT_ANALYZED)); /* //索引日志tag foreach (string tagName in journal.TagNames) { doc.Add(new Field(BlogIndexDocument.Tag, tagName.ToLower(), Field.Store.YES, Field.Index.ANALYZED)); } //索引日志用户分类名称 IEnumerable<string> ownerCategoryNames = journal.OwnerCategoryNames; if (ownerCategoryNames != null) { foreach (string ownerCategoryName in ownerCategoryNames) { doc.Add(new Field(BlogIndexDocument.OwnerCategoryName, ownerCategoryName.ToLower(), Field.Store.YES, Field.Index.ANALYZED)); } } //索引日志站点分类ID long? siteCategoryId = journal.SiteCategoryId; if (siteCategoryId.HasValue) { doc.Add(new Field(BlogIndexDocument.SiteCategoryId, siteCategoryId.Value.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); } */ return doc; }
/// <summary> /// 更新索引 /// </summary> /// <param name="journal">待更新的日志</param> public void Update(Journal journal) { Document doc = JournalIndexDocument.Convert(journal); searchEngine.Update(doc, journal.id.ToString(), JournalIndexDocument.id); }
/// <summary> /// 添加索引 /// </summary> /// <param name="journal">待添加的日志</param> public void Insert(Journal journal) { Insert(new Journal[] { journal }); }
/* //todo:wanf 分类 及 标签 索引 #region 分类增量索引 /// <summary> /// 为日志添加分类时触发 /// </summary> private void AddCategoriesToBlog_BatchAfter(IEnumerable<string> senders, TagEventArgs eventArgs) { if (eventArgs.TenantTypeId == TenantTypeIds.Instance().BlogThread()) { long blogThreadId = eventArgs.ItemId; if (journalSearcher == null) { journalSearcher = (BlogSearcher)SearcherFactory.GetSearcher(BlogSearcher.CODE); } journalSearcher.Update(journalService.Get(blogThreadId)); } } /// <summary> /// 删除和更新分类时触发 /// </summary> private void DeleteUpdateCategories_Before(Category sender, CommonEventArgs eventArgs) { if (sender.TenantTypeId == TenantTypeIds.Instance().BlogThread()) { if (eventArgs.EventOperationType == EventOperationType.Instance().Delete() || eventArgs.EventOperationType == EventOperationType.Instance().Update()) { IEnumerable<long> blogThreadIds = categoryService.GetItemIds(sender.CategoryId, false); if (journalSearcher == null) { journalSearcher = (BlogSearcher)SearcherFactory.GetSearcher(BlogSearcher.CODE); } journalSearcher.Update(journalService.GetBlogThreads(blogThreadIds)); } } } #endregion #region 标签增量索引 /// <summary> /// 为日志添加标签时触发 /// </summary> private void AddTagsToBlog_BatchAfter(IEnumerable<string> senders, TagEventArgs eventArgs) { if (eventArgs.TenantTypeId == TenantTypeIds.Instance().BlogThread()) { long blogThreadId = eventArgs.ItemId; if (journalSearcher == null) { journalSearcher = (BlogSearcher)SearcherFactory.GetSearcher(BlogSearcher.CODE); } journalSearcher.Update(journalService.Get(blogThreadId)); } } /// <summary> /// 删除和更新标签时触发 /// </summary> private void DeleteUpdateTags_Before(Tag sender, CommonEventArgs eventArgs) { if (sender.TenantTypeId==TenantTypeIds.Instance().BlogThread()) { if (eventArgs.EventOperationType==EventOperationType.Instance().Delete()||eventArgs.EventOperationType==EventOperationType.Instance().Update()) { //根据标签获取所有使用该标签的(内容项)日志 IEnumerable<long> blogThreadIds = tagService.GetItemIds(sender.TagName, null); if (journalSearcher == null) { journalSearcher = (BlogSearcher)SearcherFactory.GetSearcher(BlogSearcher.CODE); } journalSearcher.Update(journalService.GetBlogThreads(blogThreadIds)); } } } private void DeleteItemInTags(ItemInTag sender, CommonEventArgs eventArgs) { if (sender.TenantTypeId == TenantTypeIds.Instance().BlogThread()) { long barThreadId = sender.ItemId; if (journalSearcher == null) { journalSearcher = (BlogSearcher)SearcherFactory.GetSearcher(BlogSearcher.CODE); } journalSearcher.Update(journalService.Get(barThreadId)); } } #endregion */ #region 日志增量索引 /// <summary> /// 日志增量索引 /// </summary> private void Journal_After(Journal journal, CommonEventArgs eventArgs) { if (journal == null) { return; } if (journalSearcher == null) { journalSearcher = (JournalSearcher)SearcherFactory.GetSearcher(JournalSearcher.CODE); } //添加索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { journalSearcher.Insert(journal); } //删除索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { journalSearcher.Delete(journal.id); } //更新索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Update() || eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved()) { journalSearcher.Update(journal); } }