void ProcessSearchResults(SearchResults <CalculationIndex> searchResult, CalculationSearchResults results) { if (!searchResult.Facets.IsNullOrEmpty()) { results.Facets = results.Facets.Concat(searchResult.Facets); } else { results.TotalCount = (int)(searchResult?.TotalCount ?? 0); results.Results = searchResult?.Results?.Select(m => new CalculationSearchResult { Id = m.Result.Id, Name = m.Result.Name, FundingStreamId = m.Result.FundingStreamId, SpecificationId = m.Result.SpecificationId, ValueType = m.Result.ValueType, CalculationType = m.Result.CalculationType, Namespace = m.Result.Namespace, WasTemplateCalculation = m.Result.WasTemplateCalculation, Description = m.Result.Description, Status = m.Result.Status, LastUpdatedDate = m.Result.LastUpdatedDate?.LocalDateTime, SpecificationName = m.Result.SpecificationName, }); } }
void ProcessSearchResults(SearchResults <CalculationIndex> searchResult, CalculationSearchResults results) { if (!searchResult.Facets.IsNullOrEmpty()) { results.Facets = results.Facets.Concat(searchResult.Facets); } else { results.TotalCount = (int)(searchResult?.TotalCount ?? 0); results.Results = searchResult?.Results?.Select(m => new CalculationSearchResult { Id = m.Result.Id, Name = m.Result.Name, FundingPeriodName = m.Result.FundingPeriodName, SpecificationName = m.Result.SpecificationName, Status = m.Result.Status, CalculationType = m.Result.CalculationType, LastUpdatedDate = m.Result.LastUpdatedDate.ToNullableLocal() }); } }
async public Task <IActionResult> SearchCalculations(HttpRequest request) { string json = await request.GetRawBodyStringAsync(); SearchModel searchModel = JsonConvert.DeserializeObject <SearchModel>(json); if (searchModel == null || searchModel.PageNumber < 1 || searchModel.Top < 1) { _logger.Error("A null or invalid search model was provided for searching calculations"); return(new BadRequestObjectResult("An invalid search model was provided")); } if (searchModel.FacetCount < 0 || searchModel.FacetCount > 1000) { return(new BadRequestObjectResult("An invalid facet count was specified")); } IEnumerable <Task <SearchResults <CalculationIndex> > > searchTasks = BuildSearchTasks(searchModel); try { await TaskHelper.WhenAllAndThrow(searchTasks.ToArraySafe()); CalculationSearchResults results = new CalculationSearchResults(); foreach (var searchTask in searchTasks) { ProcessSearchResults(searchTask.Result, results); } return(new OkObjectResult(results)); } catch (FailedToQuerySearchException exception) { _logger.Error(exception, $"Failed to query search with term: {searchModel.SearchTerm}"); return(new StatusCodeResult(500)); } }