/// <summary> /// 群组搜索 /// </summary> public ActionResult Search(GroupFullTextQuery query) { 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> /// <param name="query">搜索条件</param> /// <param name="topNumber">显示数目</param> /// <returns></returns> public ActionResult _GlobalSearch(PhotoFullTextQuery query, int topNumber) { query.TenantTypeId = TenantTypeIds.Instance().User(); query.PageIndex = 1; query.PageSize = 20; PhotoSearcher photoSearcher = (PhotoSearcher)SearcherFactory.GetSearcher(PhotoSearcher.CODE); PagingDataSet <Photo> photos = photos = photoSearcher.Search(query); List <Photo> list = new List <Photo>(); foreach (var item in photos) { if (authorizer.Photo_Search(item.Album)) { list.Add(item); } } ViewData["photoSearcherUrl"] = photoSearcher.PageSearchActionUrl(query.Keyword); ViewData["total"] = photos.TotalRecords; ViewData["queryDuration"] = photos.QueryDuration; return(View(list.Take(topNumber))); }
/// <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()); } }
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> topicsTag = null; if (TopicSearcher.Search(query, true).Count == 0) { return(View()); } else { topicsTag = TopicSearcher.Search(query, true).AsEnumerable <TopicEntity>(); } if (topicsTag.Count() < 20) { IEnumerable <TopicEntity> topicsFollow = topicService.FollowedUserAlsoJoinedTopics(currentUser.UserId, 20 - topicsTag.Count()); return(View(topicsTag.Union(topicsFollow))); } else { return(View(topicsTag)); } } else { return(View()); } }
/// <summary> /// 供职于同一公司 /// </summary> /// <param name="pageIndex">分页页码</param> /// <returns></returns> public ActionResult _InterestedWithCompanys(int pageIndex = 1, string view = null) { IUser CurrentUser = UserContext.CurrentUser; if (CurrentUser == null) { return(null); } Dictionary <long, IEnumerable <string> > companyNameDic = null; UserSearcher searcher = (UserSearcher)SearcherFactory.GetSearcher(UserSearcher.CODE); PagingDataSet <User> users = searcher.SearchInterestedWithCompanys(CurrentUser.UserId, pageIndex, pageSize, out companyNameDic); ViewData["companyNameDic"] = companyNameDic; List <User> userList = new List <User>(); foreach (var user in users) { if (companyNameDic.ContainsKey(user.UserId) && companyNameDic[user.UserId].Count() > 0) { userList.Add(user); } } int pageCount = users.PageCount; users = new PagingDataSet <User>(userList); ViewData["pageCount"] = pageCount; if (string.IsNullOrEmpty(view)) { return(View(users)); } else { return(View(view, users)); } }
//照片增加、删除、更新、设置精华、取消精华 private void Photo_After(Photo photo, CommonEventArgs eventArgs) { if (photo == null) { return; } if (photoSearcher == null) { photoSearcher = (PhotoSearcher)SearcherFactory.GetSearcher(PhotoSearcher.CODE); } if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { photoSearcher.Insert(photo); } else if (eventArgs.EventOperationType == EventOperationType.Instance().Update() || eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved()) { photoSearcher.Update(photo); } else if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { photoSearcher.Delete(photo); } }
private void Tag_After(Tag sender, CommonEventArgs eventArgs) { if (sender == null) { return; } if (tagSearcher == null) { tagSearcher = (TagSearcher)SearcherFactory.GetSearcher(TagSearcher.CODE); } if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { tagSearcher.InsertTag(sender); } else if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { tagSearcher.DeleteTag(sender.TagId); } else if (eventArgs.EventOperationType == EventOperationType.Instance().Update()) { tagSearcher.UpdateTag(sender); } }
/// <summary> /// 可能感兴趣的人-有共同关注的人 /// </summary> /// <param name="pageIndex">分页页码</param> /// <returns></returns> public ActionResult _InterestedWithFollows(int pageIndex = 1) { IUser CurrentUser = UserContext.CurrentUser; if (CurrentUser == null) { return(null); } Dictionary <long, IEnumerable <long> > followedUserIdDic = null; Dictionary <long, User> followedUserDic = null; FollowUserSearcher searcher = (FollowUserSearcher)SearcherFactory.GetSearcher(FollowUserSearcher.CODE); PagingDataSet <User> users = searcher.SearchInterestedWithFollows(CurrentUser.UserId, pageIndex, pageSize, out followedUserIdDic, out followedUserDic); //设置当前登录用户对当前页用户的关注情况 Dictionary <long, bool> isCurrentUserFollowDic = new Dictionary <long, bool>(); foreach (var user in users) { //如果当前登录用户关注了该用户 if (followService.IsFollowed(CurrentUser.UserId, user.UserId)) { isCurrentUserFollowDic.Add(user.UserId, true); } else { isCurrentUserFollowDic.Add(user.UserId, false); } } ViewData["isCurrentUserFollowDic"] = isCurrentUserFollowDic; ViewData["followedUserIdDic"] = followedUserIdDic; ViewData["followedUserDic"] = followedUserDic; return(View(users)); }
/// <summary> /// 快捷搜索 /// </summary> /// <param name="query"></param> /// <param name="topNumber"></param> /// <returns></returns> public ActionResult _QuickSearch(PhotoFullTextQuery query, int topNumber) { query.TenantTypeId = TenantTypeIds.Instance().User(); query.PageSize = 20; query.Keyword = WebUtility.HtmlDecode(query.Keyword); query.Filter = PhotoSearchRange.DESCRIPTION; PhotoSearcher photoSearcher = (PhotoSearcher)SearcherFactory.GetSearcher(PhotoSearcher.CODE); PagingDataSet <Photo> photos = photoSearcher.Search(query); List <Photo> list = new List <Photo>(); foreach (var item in photos) { if (authorizer.Photo_Search(item.Album)) { list.Add(item); } } ViewData["total"] = photos.TotalRecords; ViewData["photoSearcherUrl"] = photoSearcher.PageSearchActionUrl(query.Keyword); return(View(list.Take(topNumber))); }
/// <summary> /// 日志增量索引 /// </summary> private void BlogThread_After(BlogThread blog, CommonEventArgs eventArgs) { if (blog == null) { return; } if (blogSearcher == null) { blogSearcher = (BlogSearcher)SearcherFactory.GetSearcher(BlogSearcher.CODE); } //添加索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { if (!blog.IsDraft) { blogSearcher.Insert(blog); } } //删除索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { blogSearcher.Delete(blog.ThreadId); } //更新索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Update()) { if (!blog.IsDraft) { blogSearcher.Update(blog); } } }
/// <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()) { //if (!journal.IsDraft) //{ 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()) { //if (!journal.IsDraft) //{ journalSearcher.Update(journal); //} } }
/// <summary> /// 微博搜索 /// </summary> /// <param name="query"></param> /// <returns></returns> public ActionResult Search(MicroblogFullTextQuery query) { query.Keyword = WebUtility.UrlDecode(query.Keyword); query.PageSize = 20;//每页记录数 //调用搜索器进行搜索 MicroblogSearcher microblogSearcher = (MicroblogSearcher)SearcherFactory.GetSearcher(MicroblogSearcher.CODE); PagingDataSet <MicroblogEntity> microblogEntities = microblogSearcher.Search(query); //添加到用户搜索历史 IUser CurrentUser = UserContext.CurrentUser; if (CurrentUser != null) { SearchHistoryService searchHistoryService = new SearchHistoryService(); searchHistoryService.SearchTerm(CurrentUser.UserId, MicroblogSearcher.CODE, query.Keyword); } //添加到热词 if (!string.IsNullOrWhiteSpace(query.Keyword)) { SearchedTermService searchedTermService = new SearchedTermService(); searchedTermService.SearchTerm(MicroblogSearcher.CODE, query.Keyword); } //设置页面Meta if (string.IsNullOrWhiteSpace(query.Keyword)) { pageResourceManager.InsertTitlePart("搜索");//设置页面Title } else { pageResourceManager.InsertTitlePart('“' + query.Keyword + '”' + "的相关微博");//设置页面Title } return(View(microblogEntities)); }
public IEnumerable <DisplayField> GetCurrentDisplayFields() { return(SearcherFactory.GetAvailableFields()); }
public SearchCapability GetCurrentSearchCapability() { return(SearcherFactory.GetSearchCapability()); }
public Searcher GetCurrentJournalSearcher() { licenceStorage.EnsureUseAllowed(); return(SearcherFactory.CreateSearcher()); }
public ActionResult _InterestedWithAll(int pageSize = 6, int pageIndex = 1, string view = null) { IUser CurrentUser = UserContext.CurrentUser; if (CurrentUser == null) { return(null); } //查询同一公司的(优先级最高) Dictionary <long, IEnumerable <string> > companyNameDic = null; UserSearcher userSearcher = (UserSearcher)SearcherFactory.GetSearcher(UserSearcher.CODE); PagingDataSet <User> usersWithCompanys = userSearcher.SearchInterestedWithCompanys(CurrentUser.UserId, 1, 30, out companyNameDic); //存储感兴趣的人 List <User> userList = usersWithCompanys.ToList(); //存储感兴趣的类型 Dictionary <long, string> interestedDic = usersWithCompanys.ToDictionary(key => key.UserId, value => "WithCompanys"); //查询有共同关注用户的(优先级第二) Dictionary <long, IEnumerable <long> > followedUserIdDic = null; Dictionary <long, User> followedUserDic = null; FollowUserSearcher followUserSearcher = (FollowUserSearcher)SearcherFactory.GetSearcher(FollowUserSearcher.CODE); PagingDataSet <User> usersWithFollows = followUserSearcher.SearchInterestedWithFollows(CurrentUser.UserId, 1, 30, out followedUserIdDic, out followedUserDic); foreach (User user in usersWithFollows) { if (!interestedDic.ContainsKey(user.UserId)) { userList.Add(user); interestedDic.Add(user.UserId, "WithFollows"); } } //查询同一个学校的(优先级第三) Dictionary <long, IEnumerable <string> > schoolNameDic = null; PagingDataSet <User> usersWithSchools = userSearcher.SearchInterestedWithSchools(CurrentUser.UserId, 1, 30, out schoolNameDic); foreach (User user in usersWithSchools) { if (!interestedDic.ContainsKey(user.UserId)) { userList.Add(user); interestedDic.Add(user.UserId, "WithSchools"); } } //查询相同标签的(优先级最低) Dictionary <long, IEnumerable <string> > tagNameDic = null; PagingDataSet <User> usersWithTags = userSearcher.SearchInterestedWithTags(CurrentUser.UserId, 1, 30, out tagNameDic); foreach (User user in usersWithTags) { if (!interestedDic.ContainsKey(user.UserId)) { userList.Add(user); interestedDic.Add(user.UserId, "WithTags"); } } ViewData["followedUserIdDic"] = followedUserIdDic; ViewData["followedUserDic"] = followedUserDic; ViewData["companyNameDic"] = companyNameDic; ViewData["schoolNameDic"] = schoolNameDic; ViewData["tagNameDic"] = tagNameDic; ViewData["interestedDic"] = interestedDic; //不指定View,则返回固定的页面,随机显示 if (string.IsNullOrEmpty(view)) { //随机从用户列表中取pageSize对应的对象组装成新的集合 List <User> randomUserList = null; if (userList.Count <= pageSize) { randomUserList = userList; } else { Dictionary <int, User> randomUserDic = new Dictionary <int, User>(); Random random = new Random(); while (randomUserDic.Count < pageSize) { int index = random.Next(0, userList.Count); if (!randomUserDic.ContainsKey(index)) { User user = userList[index]; randomUserDic.Add(index, user); } } randomUserList = randomUserDic.OrderBy(n => n.Key).Select(n => n.Value).ToList(); } return(View(randomUserList)); } //指定view,分页显示 else { ViewData["pageCount"] = userList.Count / pageSize + 1; return(View(view, userList.Skip(pageSize * (pageIndex - 1)).Take(pageSize))); } }
/// <summary> /// 群组内搜索帖子 /// </summary> /// <param name="spaceKey">群组名</param> /// <param name="keyword">关键字</param> /// <param name="pageIndex">页码</param> /// <returns>群组内搜索帖子</returns> public ActionResult Search(string spaceKey, string keyword, BarSearchRange term = BarSearchRange.ALL, int pageIndex = 1) { long barSectionId = GroupIdToGroupKeyDictionary.GetGroupId(spaceKey); var group = groupService.Get(spaceKey); if (group == null) { return(HttpNotFound()); } ViewData["group"] = group; BarSection section = barSectionService.Get(barSectionId); if (section == null) { return(HttpNotFound()); } ViewData["section"] = section; BarFullTextQuery query = new BarFullTextQuery(); query.Term = term; query.PageIndex = pageIndex; query.PageSize = 20;//每页记录数 query.Keyword = keyword; query.Range = section.SectionId.ToString(); //获取群组贴吧的帖子 query.TenantTypeId = TenantTypeIds.Instance().Group(); //根据帖吧id查询帖吧名字 query.TenantTypeId = section.TenantTypeId; ViewData["barname"] = section.Name; ViewData["TenantTypeId"] = section.TenantTypeId; //调用搜索器进行搜索 BarSearcher BarSearcher = (BarSearcher)SearcherFactory.GetSearcher(BarSearcher.CODE); PagingDataSet <BarEntity> BarEntities = BarSearcher.Search(query); if (Request.IsAjaxRequest()) { return(View("~/Applications/Bar/Views/Bar/_ListSearchThread.cshtml", BarEntities)); } //设置页面Meta if (string.IsNullOrWhiteSpace(query.Keyword)) { pageResourceManager.InsertTitlePart("群组帖子搜索");//设置页面Title } else { pageResourceManager.InsertTitlePart('“' + query.Keyword + '”' + "的相关帖子");//设置页面Title } pageResourceManager.SetMetaOfKeywords("帖吧搜索"); //设置Keyords类型的Meta pageResourceManager.SetMetaOfDescription("帖吧搜索"); //设置Description类型的Meta return(View(BarEntities)); }
/// <summary> /// Creates search and taxonomy readers over the corresponding directories. /// /// <para> /// <b>NOTE:</b> you should only use this constructor if you commit and call /// <seealso cref="#maybeRefresh()"/> in the same thread. Otherwise it could lead to an /// unsync'd <seealso cref="IndexSearcher"/> and <seealso cref="TaxonomyReader"/> pair. /// </para> /// </summary> public SearcherTaxonomyManager(Store.Directory indexDir, Store.Directory taxoDir, SearcherFactory searcherFactory) { if (searcherFactory == null) { searcherFactory = new SearcherFactory(); } this.searcherFactory = searcherFactory; var taxoReader = new DirectoryTaxonomyReader(taxoDir); Current = new SearcherAndTaxonomy(SearcherManager.GetSearcher(searcherFactory, DirectoryReader.Open(indexDir)), taxoReader); this.taxoWriter = null; taxoEpoch = -1; }
/// <summary> /// 照片搜索 /// </summary> /// <param name="query">条件</param> /// <returns></returns> public ActionResult Search(PhotoFullTextQuery query) { query.Keyword = WebUtility.UrlDecode(query.Keyword); query.TenantTypeId = TenantTypeIds.Instance().User(); query.PageSize = 20; IUser currentUser = UserContext.CurrentUser; if (currentUser != null) { if (currentUser.UserId == query.UserId) { query.IgnoreAuditAndPrivacy = true; } } ViewData["keyword"] = query.Keyword; ViewData["filter"] = query.Filter; ViewData["userId"] = query.UserId; //调用搜索器进行搜索 PhotoSearcher photoSearcher = (PhotoSearcher)SearcherFactory.GetSearcher(PhotoSearcher.CODE); PagingDataSet <Photo> photos = photoSearcher.Search(query); int minus = 0; foreach (var photo in photos) { bool isCurrentUser = true; if (currentUser != null) { isCurrentUser = query.UserId == currentUser.UserId ? true : photo.AuditStatus == AuditStatus.Success; } if (!(authorizer.Photo_Search(photo.Album) && isCurrentUser)) { minus++; } } ViewData["minus"] = minus; //添加到用户搜索历史记录 if (currentUser != null) { if (!string.IsNullOrWhiteSpace(query.Keyword)) { searchHistoryService.SearchTerm(currentUser.UserId, PhotoSearcher.CODE, query.Keyword); } } //添加到热词 if (!string.IsNullOrWhiteSpace(query.Keyword)) { searchedTermService.SearchTerm(PhotoSearcher.CODE, query.Keyword); } //设置页面Meta if (string.IsNullOrWhiteSpace(query.Keyword)) { pageResourceManager.InsertTitlePart("照片搜索"); } else { pageResourceManager.InsertTitlePart(query.Keyword + "的相关照片"); } return(View(photos)); }