/// <summary> /// 全文检索瀑布流 /// </summary> /// <param name="query"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public ActionResult _SearchWaterFall(PhotoFullTextQuery query, int pageIndex = 1, int pageSize = 20) { query.TenantTypeId = TenantTypeIds.Instance().User(); query.PageSize = pageSize; query.PageIndex = pageIndex; IUser currentUser = UserContext.CurrentUser; if (currentUser != null && currentUser.UserId == query.UserId) { query.IgnoreAuditAndPrivacy = true; } //调用搜索器进行搜索 PhotoSearcher photoSearcher = (PhotoSearcher)SearcherFactory.GetSearcher(PhotoSearcher.CODE); PagingDataSet <Photo> photos = photoSearcher.Search(query); return(View(photos)); }
/// <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> /// <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> /// <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)); }