public IActionResult Search() { LuceneHelper lHelper = new LuceneHelper(_hostingEnvironment.WebRootPath); lHelper.Search("神农"); lHelper.Search("六月份"); return(View()); }
public async Task <ActionResult> Search(string wd = "", int page = 1, int size = 10) { var nul = new List <PostOutputDto>(); int count = 0; ViewBag.Elapsed = 0; ViewBag.Total = count; ViewBag.Keyword = wd; if (Regex.Match(wd, CommonHelper.BanRegex).Length > 0 || Regex.Match(wd, CommonHelper.ModRegex).Length > 0) { //ViewBag.Wd = ""; return(RedirectToAction("Search")); } var hotSearches = new List <KeywordsRankOutputDto>(); ViewBag.hotSearches = hotSearches; using (RedisHelper redisHelper = RedisHelper.GetInstance()) { string key = Request.UserHostAddress + Request.UserAgent; if (redisHelper.KeyExists(key) && !redisHelper.GetString(key).Equals(wd)) { ViewBag.ErrorMsg = "10秒内只能搜索1次!"; return(View(nul)); } redisHelper.SetString(key, wd, TimeSpan.FromSeconds(10)); } wd = wd.Trim().Replace("+", " "); var sw = new Stopwatch(); if (!string.IsNullOrWhiteSpace(wd) && !wd.Contains("锟斤拷")) { if (page == 1) { SearchDetailsBll.AddEntity(new SearchDetails() { KeyWords = wd, SearchTime = DateTime.Now, IP = Request.UserHostAddress }); } sw.Start(); var query = LuceneHelper.Search(wd).ToList(); var posts = query.Skip((page - 1) * size).Take(size).ToList(); sw.Stop(); ViewBag.Elapsed = sw.Elapsed.TotalMilliseconds; ViewBag.Total = query.Count; SearchDetailsBll.SaveChanges(); return(View(posts)); } var start = DateTime.Today.AddDays(-7); hotSearches = (await SearchDetailsBll.LoadEntitiesFromCacheNoTrackingAsync(s => s.SearchTime > start, s => s.SearchTime, false).ConfigureAwait(true)).GroupBy(s => s.KeyWords.ToLower()).OrderByDescending(g => g.Count()).Take(7).Select(g => new KeywordsRankOutputDto() { KeyWords = g.FirstOrDefault()?.KeyWords, SearchCount = g.Count() }).ToList(); ViewBag.hotSearches = hotSearches; return(View(nul)); }
/// <summary> /// 查询Lucene.NET /// </summary> /// <param name="top">数量</param> /// <param name="site_id">网站ID</param> /// <param name="channel_id">频道ID</param> /// <param name="category_id">类别ID</param> /// <param name="keyword">关键词</param> /// <returns></returns> public DataTable get_lucene_list(int top, int site_id, int channel_id, int category_id, string keywords) { DataTable dt = new DataTable(); if (site_id > 0 && null != keywords && keywords.Length > 1) { dt = LuceneHelper.Search(LuceneHelper.INDEX_DIR, top, site_id, channel_id, category_id, keywords); } return(dt); }
/// <summary> /// 查询Lucene.NET /// </summary> /// <param name="pageSize">每页显示数量</param> /// <param name="pageIndex">当前分页</param> /// <param name="site_id">网站ID</param> /// <param name="channel_id">频道ID</param> /// <param name="category_id">类别ID</param> /// <param name="keyword">关键词</param> /// <param name="recordCount">结果总数量</param> /// <returns></returns> public DataTable get_lucene_list(int pageSize, int pageIndex, int site_id, int channel_id, int category_id, string keywords, out int recordCount) { recordCount = 0; DataTable dt = new DataTable(); if (site_id > 0 && null != keywords && keywords.Length > 0) { dt = LuceneHelper.Search(LuceneHelper.INDEX_DIR, pageSize, pageIndex, site_id, channel_id, category_id, keywords, out recordCount); } return(dt); }