/// <summary> /// 专题增量索引 /// </summary> private void TopicEntity_After(TopicEntity group, CommonEventArgs eventArgs) { if (group == null) { return; } if (groupSearcher == null) { groupSearcher = (TopicSearcher)SearcherFactory.GetSearcher(TopicSearcher.CODE); } //添加索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { groupSearcher.Insert(group); } //删除索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { groupSearcher.Delete(group.TopicId); } //更新索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Update() || eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved()) { groupSearcher.Update(group); } }
/// <summary> /// 专题搜索自动完成 /// </summary> public JsonResult SearchAutoComplete(string keyword, int topNumber) { //调用搜索器进行搜索 TopicSearcher groupSearcher = (TopicSearcher)SearcherFactory.GetSearcher(TopicSearcher.CODE); IEnumerable <string> terms = groupSearcher.AutoCompleteSearch(keyword, topNumber); var jsonResult = Json(terms.Select(t => new { tagName = t, tagNameWithHighlight = SearchEngine.Highlight(keyword, string.Join("", t.Take(34)), 100) }), JsonRequestBehavior.AllowGet); return(jsonResult); }
/// <summary> /// 专题全局搜索 /// </summary> public ActionResult _GlobalSearch(TopicFullTextQuery query, int topNumber) { query.PageSize = topNumber;//每页记录数 query.PageIndex = 1; //调用搜索器进行搜索 TopicSearcher groupSearcher = (TopicSearcher)SearcherFactory.GetSearcher(TopicSearcher.CODE); PagingDataSet <TopicEntity> groups = groupSearcher.Search(query); return(PartialView(groups)); }
/// <summary> /// 专题快捷搜索 /// </summary> public ActionResult _QuickSearch(TopicFullTextQuery query, int topNumber) { query.PageSize = topNumber;//每页记录数 query.PageIndex = 1; query.Range = TopicSearchRange.GROUPNAME; query.Keyword = Server.UrlDecode(query.Keyword); //调用搜索器进行搜索 TopicSearcher TopicSearcher = (TopicSearcher)SearcherFactory.GetSearcher(TopicSearcher.CODE); PagingDataSet <TopicEntity> groups = TopicSearcher.Search(query); return(PartialView(groups)); }
/// <summary> /// 为专题添加标签时触发 /// </summary> private void AddTagsToTopic_BatchAfter(IEnumerable <string> senders, TagEventArgs eventArgs) { if (eventArgs.TenantTypeId == TenantTypeIds.Instance().Topic()) { long groupId = eventArgs.ItemId; if (groupSearcher == null) { groupSearcher = (TopicSearcher)SearcherFactory.GetSearcher(TopicSearcher.CODE); } groupSearcher.Update(topicService.Get(groupId)); } }
private void DeleteItemInTags(ItemInTag sender, CommonEventArgs eventArgs) { if (sender.TenantTypeId == TenantTypeIds.Instance().Topic()) { long groupId = sender.ItemId; if (groupSearcher == null) { groupSearcher = (TopicSearcher)SearcherFactory.GetSearcher(TopicSearcher.CODE); } groupSearcher.Update(topicService.Get(groupId)); } }
/// <summary> /// 删除和更新分类时触发 /// </summary> private void DeleteUpdateCategories_Before(Category sender, CommonEventArgs eventArgs) { if (sender.TenantTypeId == TenantTypeIds.Instance().Topic()) { if (eventArgs.EventOperationType == EventOperationType.Instance().Delete() || eventArgs.EventOperationType == EventOperationType.Instance().Update()) { IEnumerable <long> groupIds = categoryService.GetItemIds(sender.CategoryId, false); if (groupSearcher == null) { groupSearcher = (TopicSearcher)SearcherFactory.GetSearcher(TopicSearcher.CODE); } groupSearcher.Update(topicService.GetTopicEntitiesByIds(groupIds)); } } }
/// <summary> /// 删除和更新标签时触发 /// </summary> private void DeleteUpdateTags_Before(Tag sender, CommonEventArgs eventArgs) { if (sender.TenantTypeId == TenantTypeIds.Instance().Topic()) { if (eventArgs.EventOperationType == EventOperationType.Instance().Delete() || eventArgs.EventOperationType == EventOperationType.Instance().Update()) { //根据标签获取所有使用该标签的(内容项)专题 IEnumerable <long> groupIds = tagService.GetItemIds(sender.TagName, null); if (groupSearcher == null) { groupSearcher = (TopicSearcher)SearcherFactory.GetSearcher(TopicSearcher.CODE); } groupSearcher.Update(topicService.GetTopicEntitiesByIds(groupIds)); } } }
/// <summary> /// 专题搜索 /// </summary> public ActionResult Search(TopicFullTextQuery query) { query.Keyword = WebUtility.UrlDecode(query.Keyword); query.PageSize = 20;//每页记录数 //调用搜索器进行搜索 TopicSearcher groupSearcher = (TopicSearcher)SearcherFactory.GetSearcher(TopicSearcher.CODE); PagingDataSet <TopicEntity> groups = groupSearcher.Search(query); //添加到用户搜索历史 IUser CurrentUser = UserContext.CurrentUser; if (CurrentUser != null) { if (!string.IsNullOrWhiteSpace(query.Keyword)) { SearchHistoryService searchHistoryService = new SearchHistoryService(); searchHistoryService.SearchTerm(CurrentUser.UserId, TopicSearcher.CODE, query.Keyword); } } //添加到热词 if (!string.IsNullOrWhiteSpace(query.Keyword)) { SearchedTermService searchedTermService = new SearchedTermService(); searchedTermService.SearchTerm(TopicSearcher.CODE, query.Keyword); } //设置页面Meta if (string.IsNullOrWhiteSpace(query.Keyword)) { pageResourceManager.InsertTitlePart("专题搜索");//设置页面Title } else { pageResourceManager.InsertTitlePart('“' + query.Keyword + '”' + "的相关专题");//设置页面Title } return(View(groups)); }
public ActionResult _InterestTopic() { TagService tagService = new TagService(TenantTypeIds.Instance().User()); IUser currentUser = UserContext.CurrentUser; if (currentUser != null) { TopicFullTextQuery query = new TopicFullTextQuery(); query.PageSize = 20; query.PageIndex = 1; query.Range = TopicSearchRange.TAG; query.Tags = tagService.GetTopTagsOfItem(currentUser.UserId, 100).Select(n => n.TagName); query.TopicIds = topicService.GetMyJoinedTopics(currentUser.UserId, 100, 1).Select(n => n.TopicId.ToString()); //调用搜索器进行搜索 TopicSearcher TopicSearcher = (TopicSearcher)SearcherFactory.GetSearcher(TopicSearcher.CODE); IEnumerable <TopicEntity> groupsTag = null; if (TopicSearcher.Search(query, true).Count == 0) { return(View()); } else { groupsTag = TopicSearcher.Search(query, true).AsEnumerable <TopicEntity>(); } if (groupsTag.Count() < 20) { IEnumerable <TopicEntity> groupsFollow = topicService.FollowedUserAlsoJoinedTopics(currentUser.UserId, 20 - groupsTag.Count()); return(View(groupsTag.Union(groupsFollow))); } else { return(View(groupsTag)); } } else { return(View()); } }