/// <summary> /// 群组增量索引 /// </summary> private void GroupEntity_After(GroupEntity group, CommonEventArgs eventArgs) { if (group == null) { return; } if (groupSearcher == null) { groupSearcher = (GroupSearcher)SearcherFactory.GetSearcher(GroupSearcher.CODE); } //添加索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { groupSearcher.Insert(group); } //删除索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { groupSearcher.Delete(group.GroupId); } //更新索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Update()) { groupSearcher.Update(group); } }
/// <summary> /// 群组搜索自动完成 /// </summary> public JsonResult SearchAutoComplete(string keyword, int topNumber) { //调用搜索器进行搜索 GroupSearcher groupSearcher = (GroupSearcher)SearcherFactory.GetSearcher(GroupSearcher.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(GroupFullTextQuery query, int topNumber) { query.PageSize = topNumber;//每页记录数 query.PageIndex = 1; //调用搜索器进行搜索 GroupSearcher groupSearcher = (GroupSearcher)SearcherFactory.GetSearcher(GroupSearcher.CODE); PagingDataSet <GroupEntity> groups = groupSearcher.Search(query); return(PartialView(groups)); }
/// <summary> /// 群组快捷搜索 /// </summary> public ActionResult _QuickSearch(GroupFullTextQuery query, int topNumber) { query.PageSize = topNumber;//每页记录数 query.PageIndex = 1; query.Range = GroupSearchRange.GROUPNAME; query.Keyword = Server.UrlDecode(query.Keyword); //调用搜索器进行搜索 GroupSearcher GroupSearcher = (GroupSearcher)SearcherFactory.GetSearcher(GroupSearcher.CODE); PagingDataSet <GroupEntity> groups = GroupSearcher.Search(query); return(PartialView(groups)); }
/// <summary> /// 为群组添加标签时触发 /// </summary> private void AddTagsToGroup_BatchAfter(IEnumerable <string> senders, TagEventArgs eventArgs) { if (eventArgs.TenantTypeId == TenantTypeIds.Instance().Group()) { long groupId = eventArgs.ItemId; if (groupSearcher == null) { groupSearcher = (GroupSearcher)SearcherFactory.GetSearcher(GroupSearcher.CODE); } groupSearcher.Update(groupService.Get(groupId)); } }
private void DeleteItemInTags(ItemInTag sender, CommonEventArgs eventArgs) { if (sender.TenantTypeId == TenantTypeIds.Instance().Group()) { long groupId = sender.ItemId; if (groupSearcher == null) { groupSearcher = (GroupSearcher)SearcherFactory.GetSearcher(GroupSearcher.CODE); } groupSearcher.Update(groupService.Get(groupId)); } }
/// <summary> /// 删除和更新分类时触发 /// </summary> private void DeleteUpdateCategories_Before(Category sender, CommonEventArgs eventArgs) { if (sender.TenantTypeId == TenantTypeIds.Instance().Group()) { if (eventArgs.EventOperationType == EventOperationType.Instance().Delete() || eventArgs.EventOperationType == EventOperationType.Instance().Update()) { IEnumerable <long> groupIds = categoryService.GetItemIds(sender.CategoryId, false); if (groupSearcher == null) { groupSearcher = (GroupSearcher)SearcherFactory.GetSearcher(GroupSearcher.CODE); } groupSearcher.Update(groupService.GetGroupEntitiesByIds(groupIds)); } } }
/// <summary> /// 删除和更新标签时触发 /// </summary> private void DeleteUpdateTags_Before(Tag sender, CommonEventArgs eventArgs) { if (sender.TenantTypeId == TenantTypeIds.Instance().Group()) { if (eventArgs.EventOperationType == EventOperationType.Instance().Delete() || eventArgs.EventOperationType == EventOperationType.Instance().Update()) { //根据标签获取所有使用该标签的(内容项)群组 IEnumerable <long> groupIds = tagService.GetItemIds(sender.TagName, null); if (groupSearcher == null) { groupSearcher = (GroupSearcher)SearcherFactory.GetSearcher(GroupSearcher.CODE); } groupSearcher.Update(groupService.GetGroupEntitiesByIds(groupIds)); } } }
/// <summary> /// 群组搜索 /// </summary> public ActionResult Search(GroupFullTextQuery query) { query.Keyword = WebUtility.UrlDecode(query.Keyword); query.PageSize = 20;//每页记录数 //调用搜索器进行搜索 GroupSearcher groupSearcher = (GroupSearcher)SearcherFactory.GetSearcher(GroupSearcher.CODE); PagingDataSet <GroupEntity> groups = groupSearcher.Search(query); //添加到用户搜索历史 IUser CurrentUser = UserContext.CurrentUser; if (CurrentUser != null) { if (!string.IsNullOrWhiteSpace(query.Keyword)) { SearchHistoryService searchHistoryService = new SearchHistoryService(); searchHistoryService.SearchTerm(CurrentUser.UserId, GroupSearcher.CODE, query.Keyword); } } //添加到热词 if (!string.IsNullOrWhiteSpace(query.Keyword)) { SearchedTermService searchedTermService = new SearchedTermService(); searchedTermService.SearchTerm(GroupSearcher.CODE, query.Keyword); } //设置页面Meta if (string.IsNullOrWhiteSpace(query.Keyword)) { pageResourceManager.InsertTitlePart("群组搜索");//设置页面Title } else { pageResourceManager.InsertTitlePart('“' + query.Keyword + '”' + "的相关群组");//设置页面Title } return(View(groups)); }
/// <summary> /// 可能感兴趣的群组 /// </summary> public ActionResult _InterestGroup() { TagService tagService = new TagService(TenantTypeIds.Instance().User()); IUser currentUser = UserContext.CurrentUser; if (currentUser != null) { GroupFullTextQuery query = new GroupFullTextQuery(); query.PageSize = 20; query.PageIndex = 1; query.Range = GroupSearchRange.TAG; query.Tags = tagService.GetTopTagsOfItem(currentUser.UserId, 100).Select(n => n.TagName); query.GroupIds = groupService.GetMyJoinedGroups(currentUser.UserId, 100, 1).Select(n => n.GroupId.ToString()); //调用搜索器进行搜索 GroupSearcher GroupSearcher = (GroupSearcher)SearcherFactory.GetSearcher(GroupSearcher.CODE); IEnumerable <GroupEntity> groupsTag = null; if (GroupSearcher.Search(query, true).Count == 0) { return(View()); } else { groupsTag = GroupSearcher.Search(query, true).AsEnumerable <GroupEntity>(); } if (groupsTag.Count() < 20) { IEnumerable <GroupEntity> groupsFollow = groupService.FollowedUserAlsoJoinedGroups(currentUser.UserId, 20 - groupsTag.Count()); return(View(groupsTag.Union(groupsFollow))); } else { return(View(groupsTag)); } } else { return(View()); } }