Пример #1
0
        public IEnumerable <FrameworkProviderSearchResultsItem> GetProvidersByFrameworkId(string frameworkId)
        {
            var take = _queryHelper.GetProvidersByFrameworkTotalAmount(frameworkId);

            var results =
                _elasticsearchCustomClient.Search <FrameworkProviderSearchResultsItem>(
                    s =>
                    s.Index(_applicationSettings.ProviderIndexAlias)
                    .From(0)
                    .Sort(sort => sort.Ascending(f => f.Ukprn))
                    .Take(take)
                    .Query(q => q
                           .Terms(t => t
                                  .Field(f => f.FrameworkId)
                                  .Terms(frameworkId))));

            if (results.ApiCall.HttpStatusCode != 200)
            {
                _applicationLogger.LogWarning($"httpStatusCode was {results.ApiCall.HttpStatusCode}");
                throw new ApplicationException("Failed query providers by standard code");
            }

            if (results.Documents.Count > 1)
            {
                _applicationLogger.LogWarning($"found {results.Documents.Count} providers for the framework {frameworkId}");
            }

            return(results.Documents);
        }