/// <summary> /// 微博搜索 /// </summary> /// <param name="query"></param> /// <returns></returns> public ActionResult Search(MicroblogFullTextQuery query) { 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 ActionResult _List(SortBy_Microblog?sortBy = null, long?tagGroupId = null, int pageIndex = 1) { //获取微博分页数据 PagingDataSet <MicroblogEntity> microblogs = null; if (tagGroupId.HasValue && tagGroupId.Value > 0) { IEnumerable <string> tagNames = tagService.GetTagsOfGroup(tagGroupId.Value); MicroblogFullTextQuery query = new MicroblogFullTextQuery(); query.PageIndex = pageIndex; query.PageSize = 30;//每页记录数 query.Keywords = tagNames; //调用搜索器进行搜索 MicroblogSearcher microblogSearcher = (MicroblogSearcher)SearcherFactory.GetSearcher(MicroblogSearcher.CODE); microblogs = microblogSearcher.Search(query); } else { microblogs = microblogService.GetPagings(pageIndex, tenantTypeId: TenantTypeIds.Instance().User(), sortBy: sortBy ?? SortBy_Microblog.DateCreated); ////当第一次加载页面时获取当前页的最新一条微博的ID //if (pageIndex == 1) //{ // ViewData["lastMicroblogId"] = microblogs.OrderByDescending(m => m.MicroblogId).Select(m => m.MicroblogId).FirstOrDefault(); //} } return(View(microblogs)); }
/// <summary> /// 微博快捷搜索 /// </summary> /// <param name="query"></param> /// <returns></returns> public ActionResult _QuickSearch(MicroblogFullTextQuery query, int topNumber) { query.PageSize = topNumber;//每页记录数 query.PageIndex = 1; query.IsGroup = false; //调用搜索器进行搜索 MicroblogSearcher microblogSearcher = (MicroblogSearcher)SearcherFactory.GetSearcher(MicroblogSearcher.CODE); PagingDataSet <MicroblogEntity> microblogEntities = microblogSearcher.Search(query); return(PartialView(microblogEntities)); }
/// <summary> /// 微博搜索自动完成 /// </summary> /// <param name="keyword"></param> /// <returns></returns> public JsonResult SearchAutoComplete(string keyword, int topNumber) { //调用搜索器进行搜索 MicroblogSearcher microblogSearcher = (MicroblogSearcher)SearcherFactory.GetSearcher(MicroblogSearcher.CODE); IEnumerable <string> topics = microblogSearcher.AutoCompleteSearch(keyword, topNumber); if (topics != null) { var jsonResult = Json(topics.Select(t => new { tagName = t, tagNameWithHighlight = SearchEngine.Highlight(keyword, string.Join("", t.Take(34)), 100) }), JsonRequestBehavior.AllowGet); return(jsonResult); } return(null); }
/// <summary> /// 翻页获取微博(图片模式 按标签分组搜时) /// </summary> /// <param name="tagGroupId"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public ActionResult _WaterfallGetMicroblogByTagGroup(long tagGroupId, int pageIndex = 1, int pageSize = 30) { IEnumerable <string> tagNames = tagService.GetTagsOfGroup(tagGroupId); MicroblogFullTextQuery query = new MicroblogFullTextQuery(); query.PageIndex = pageIndex; query.PageSize = pageSize;//每页记录数 query.Keywords = tagNames; //调用搜索器进行搜索 MicroblogSearcher microblogSearcher = (MicroblogSearcher)SearcherFactory.GetSearcher(MicroblogSearcher.CODE); PagingDataSet <MicroblogEntity> microblogEntities = microblogSearcher.Search(query); return(View("_Waterfall", microblogEntities.AsEnumerable <MicroblogEntity>())); }
/// <summary> /// 话题详情页 /// </summary> /// <returns></returns> public ActionResult Topic(string topic) { IUser CurrentUser = UserContext.CurrentUser; if (CurrentUser == null) { return(Redirect(SiteUrls.Instance().Login(true))); } Tag tag = tagService.Get(topic); if (tag == null) { return(HttpNotFound()); } FavoriteService FavoriteService = new FavoriteService(TenantTypeIds.Instance().Tag()); bool isFavorited = FavoriteService.IsFavorited(tag.TagId, CurrentUser.UserId); ViewData["isFavorited"] = isFavorited; pageResourceManager.InsertTitlePart(tag.TagName); if (!string.IsNullOrEmpty(tag.Description)) { pageResourceManager.SetMetaOfDescription(HtmlUtility.StripHtml(tag.Description, true, false)); } //话题下有没有微博 string tagName = tag.TagName; //调用搜索器进行搜索 MicroblogFullTextQuery query = new MicroblogFullTextQuery(); query.PageIndex = 1; query.PageSize = 20;//每页记录数 query.Keywords = new List <string> { tagName }; MicroblogSearcher microblogSearcher = (MicroblogSearcher)SearcherFactory.GetSearcher(MicroblogSearcher.CODE); PagingDataSet <MicroblogEntity> microblogEntities = microblogSearcher.Search(query); ViewData["microblogEntities"] = microblogEntities; return(View(tag)); }
/// <summary> /// 话题相关的微博列表 /// </summary> /// <param name="tagId"></param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <returns></returns> public ActionResult _TopicMicroblogList(long tagId, int pageSize = 20, int pageIndex = 1) { Tag tag = tagService.Get(tagId); string tagName = tag.TagName; //调用搜索器进行搜索 MicroblogFullTextQuery query = new MicroblogFullTextQuery(); query.PageIndex = pageIndex; query.PageSize = pageSize;//每页记录数 query.Keywords = new List <string> { tagName }; MicroblogSearcher microblogSearcher = (MicroblogSearcher)SearcherFactory.GetSearcher(MicroblogSearcher.CODE); PagingDataSet <MicroblogEntity> microblogEntities = microblogSearcher.Search(query); return(View(microblogEntities)); }