/// <summary> /// Creates a discover page module. /// </summary> /// <param name="lucene">A Lucene client.</param> public DiscoverModule(LuceneWrapper lucene) { this.RequiresAuthentication(); _lucene = lucene; var paginator = new Paginator(); Get("/discover", parameters => { ViewBag.CurrentUser = Context.CurrentUser.Identity.Name; var request = this.BindAndValidate <SearchRequest>(); var searchResult = _lucene.Search(request); ViewBag.Query = request.Query; var pageBlock = paginator.GetPages(string.Format("{0}{1}", Request.Url.SiteBase, Request.Url.Path), request, searchResult, 2); var model = new PagedResult <LogEventData>(searchResult.Data, pageBlock.Pages, searchResult.TotalCount, pageBlock.TotalPages); return(Negotiate .WithModel(model) .WithView("discover.html")); }); }
public ApiStatisticsModule(LuceneWrapper lucene) : base("api/v1/") { Get("/stats", parameters => { var request = new SearchRequest(); var to = DateTime.Parse("08.01.2018").AddDays(1); var from = to.AddMonths(-5); request.Query = string.Format("Timestamp:[{0} TO {1}]", from.ToString("yyyyMMdd"), to.ToString("yyyyMMdd")); request.Limit = 1000; var logs = lucene.Search(request); var result = logs.Data .GroupBy(x => x.Timestamp.Date) .Select(x => new { Date = x.Key.ToString("yyyyMMdd"), Statistics = x.ToLookup(y => y.Level) .ToDictionary(y => y.Key.ToString(), y => y.Count()) }) .ToArray(); return(Response.AsJson(result)); }); }
/// <summary> /// Creates a search api module. /// </summary> public ApiSearchModule(LuceneWrapper lucene) : base("api/v1/") { Get("/search", parameters => { var request = this.BindAndValidate <SearchRequest>(); var validationResult = this.ModelValidationResult; if (!validationResult.IsValid) { var negotiator = Negotiate.WithModel(validationResult); if (request.SuppressResponseCodes) { return(negotiator.WithStatusCode(HttpStatusCode.OK)); } else { return(negotiator.WithStatusCode(HttpStatusCode.BadRequest)); } } var result = lucene.Search(request); return(Negotiate.WithModel(result).WithFullNegotiation()); }); }
/// <summary> /// Creates a index actor. /// </summary> /// <param name="lucene">An instance of lucene wrapper.</param> public Indexer(LuceneWrapper lucene) { _lucene = lucene; Receive <Document>(doc => { lucene.AddDocument(doc); }); }