/// <summary> /// 百科全局搜索 /// </summary> public ActionResult _GlobalSearch(WikiFullTextQuery query, int topNumber) { query.PageSize = topNumber;//每页记录数 query.PageIndex = 1; //调用搜索器进行搜索 WikiSearcher wikiSearcher = (WikiSearcher)SearcherFactory.GetSearcher(WikiSearcher.CODE); PagingDataSet <WikiPage> wikiPages = wikiSearcher.Search(query); return(PartialView(wikiPages)); }
private static void PrintResults(string searchString, WikiSearchSettings searchSettings = null) { WikiSearchResponse response = WikiSearcher.Search(searchString, searchSettings); Console.WriteLine($"\nResults found ({searchString}):\n"); foreach (WikiSearchResult result in response.Query.SearchResults) { Console.WriteLine( $"\t{result.Title} ({result.WordCount} words, {result.Size} bytes, id {result.PageId}):\t{result.Preview}...\n\tAt {result.Url(searchSettings.Language)} and {result.ConstantUrl(searchSettings.Language)}\n\tLast edited at {result.LastEdited}\n"); } }
/// <summary> /// 百科快捷搜索 /// </summary> public ActionResult _QuickSearch(WikiFullTextQuery query, int topNumber) { query.PageSize = topNumber;//每页记录数 query.PageIndex = 1; query.Range = WikiSearchRange.Title; query.Keyword = Server.UrlDecode(query.Keyword); //调用搜索器进行搜索 WikiSearcher wikiSearcher = (WikiSearcher)SearcherFactory.GetSearcher(WikiSearcher.CODE); PagingDataSet <WikiPage> blogThreads = wikiSearcher.Search(query); return(PartialView(blogThreads)); }
/// <summary> /// 百科搜索 /// </summary> public ActionResult Search(WikiFullTextQuery query) { query.Keyword = WebUtility.UrlDecode(query.Keyword); query.PageSize = 20;//每页记录数 //调用搜索器进行搜索 WikiSearcher wikiSearcher = (WikiSearcher)SearcherFactory.GetSearcher(WikiSearcher.CODE); PagingDataSet <WikiPage> wikiPages = wikiSearcher.Search(query); //添加到用户搜索历史 IUser CurrentUser = UserContext.CurrentUser; if (CurrentUser != null) { if (!string.IsNullOrWhiteSpace(query.Keyword)) { SearchHistoryService searchHistoryService = new SearchHistoryService(); searchHistoryService.SearchTerm(CurrentUser.UserId, WikiSearcher.CODE, query.Keyword); } } //添加到热词 if (!string.IsNullOrWhiteSpace(query.Keyword)) { SearchedTermService searchedTermService = new SearchedTermService(); searchedTermService.SearchTerm(WikiSearcher.CODE, query.Keyword); } //获取站点分类,并设置站点分类的选中项 IEnumerable <Category> siteCategories = categoryService.GetRootCategories(TenantTypeIds.Instance().WikiPage());// categoryService.GetOwnerCategories(0, TenantTypeIds.Instance().Wiki()); SelectList siteCategoryList = new SelectList(siteCategories.Select(n => new { text = n.CategoryName, value = n.CategoryId }), "value", "text", query.SiteCategoryId); ViewData["siteCategoryList"] = siteCategoryList; //设置页面Meta if (string.IsNullOrWhiteSpace(query.Keyword)) { pageResourceManager.InsertTitlePart("百科搜索");//设置页面Title } else { pageResourceManager.InsertTitlePart(query.Keyword + "的相关百科");//设置页面Title } return(View(wikiPages)); }
private async Task WikiSearch(string search, ISocketMessageChannel channel, int maxSearch = 10) { EmbedBuilder embed = new EmbedBuilder(); StringBuilder sb = new StringBuilder(); embed.WithTitle($"Wikipedia Search '{search}'"); embed.WithColor(FunCmdsConfig.wikipediaSearchColor); embed.WithFooter($"Search by {Context.User}", Context.User.GetAvatarUrl()); embed.WithCurrentTimestamp(); embed.WithDescription("Searching Wikipedia..."); RestUserMessage message = await channel.SendMessageAsync("", false, embed.Build()); WikiSearchResponse response = WikiSearcher.Search(search, new WikiSearchSettings { ResultLimit = maxSearch }); foreach (WikiSearchResult result in response.Query.SearchResults) { string link = $"**[{result.Title}]({result.ConstantUrl("en")})** (Words: {result.WordCount})\n{result.Preview}\n\n"; //There is a character limit of 2048, so lets make sure we don't hit that if (sb.Length >= 2048) { continue; } if (sb.Length + link.Length >= 2048) { continue; } sb.Append(link); } embed.WithDescription(sb.ToString()); embed.WithCurrentTimestamp(); await MessageUtils.ModifyMessage(message, embed); }