public ActionResult Hledat(Lib.Searching.DotaceSearchResult model) { if (model == null || ModelState.IsValid == false) { return(View(new Lib.Searching.DotaceSearchResult())); } var aggs = new Nest.AggregationContainerDescriptor <Dotace>() .Sum("souhrn", s => s .Field(f => f.DotaceCelkem) ); var res = _dotaceService.SimpleSearch(model, anyAggregation: aggs); Lib.Data.Audit.Add( Lib.Data.Audit.Operations.UserSearch , this.User?.Identity?.Name , this.Request.UserHostAddress , "Dotace" , res.IsValid ? "valid" : "invalid" , res.Q, res.OrigQuery); return(View(res)); }
public SearchResultDTO <Lib.Data.Dotace.Dotace> Hledat([FromUri] string dotaz = null, [FromUri] int?strana = null, [FromUri] int?razeni = null) { if (strana < 1) { strana = 1; } if (strana * ApiV2Controller.DefaultResultPageSize > ApiV2Controller.MaxResultsFromES) { throw new HttpResponseException(new ErrorMessage(System.Net.HttpStatusCode.BadRequest, $"Hodnota 'strana' nemůže být větší než {ApiV2Controller.MaxResultsFromES / ApiV2Controller.DefaultResultPageSize}")); } Lib.Searching.DotaceSearchResult result = null; if (string.IsNullOrWhiteSpace(dotaz)) { throw new HttpResponseException(new ErrorMessage(System.Net.HttpStatusCode.BadRequest, $"Hodnota dotaz chybí.")); } result = new Lib.Data.Dotace.DotaceService().SimpleSearch(dotaz, strana.Value, ApiV2Controller.DefaultResultPageSize, (razeni ?? 0).ToString()); if (result.IsValid == false) { throw new HttpResponseException(new ErrorMessage(System.Net.HttpStatusCode.BadRequest, $"Špatně nastavená hodnota dotaz=[{dotaz}]")); } else { var filtered = result.ElasticResults.Hits .Select(m => m.Source) .ToArray(); return(new SearchResultDTO <Lib.Data.Dotace.Dotace>(result.Total, result.Page, filtered)); } }