示例#1
0
        public async Task <int> GetIndexedDocumentsCountAsync(string indexName, GetSearchIndexDocumentCountOptions options = null)
        {
            options ??= GetSearchIndexDocumentCountOptions.Default;
            var baseUri = GetIndexedDocumentCountUri(indexName);

            Logger.LogInformation($"Trying to get index document count with name {indexName} - {baseUri}");

            try
            {
                var result = await _client.GetAsync(baseUri, options.TokenValue).ConfigureAwait(false);

                if (result.StatusCode == HttpStatusCode.NotFound)
                {
                    throw new SearchIndexNotFound(indexName);
                }

                result.EnsureSuccessStatusCode();
                return(JsonConvert.DeserializeObject <int>(await result.Content.ReadAsStringAsync().ConfigureAwait(false)));
            }
            catch (Exception exception)
            {
                Logger.LogError(exception, $"Failed to get index document count with name {indexName} - {baseUri}");
                throw;
            }
        }
示例#2
0
        public static Task <int> GetIndexedDocumentsCountAsync(this ISearchIndexManager manager, string indexName, Action <GetSearchIndexDocumentCountOptions> configureOptions)
        {
            var options = new GetSearchIndexDocumentCountOptions();

            configureOptions(options);

            return(manager.GetIndexedDocumentsCountAsync(indexName, options));
        }