Beispiel #1
0
        protected virtual async Task DeleteIndexAsync(string documentType, Action <IndexingProgress> progressCallback, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            progressCallback?.Invoke(new IndexingProgress($"{documentType}: deleting index", documentType));
            await _searchProvider.DeleteIndexAsync(documentType);
        }
Beispiel #2
0
        public virtual async Task IndexAsync(IndexingOptions options, Action <IndexingProgress> progressCallback,
                                             ICancellationToken cancellationToken)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (string.IsNullOrEmpty(options.DocumentType))
            {
                throw new ArgumentNullException($"{nameof(options)}.{nameof(options.DocumentType)}");
            }

            if (options.BatchSize == null)
            {
                options.BatchSize =
                    _settingsManager?.GetValue(ModuleConstants.Settings.General.IndexPartitionSize.Name, 50) ?? 50;
            }
            if (options.BatchSize < 1)
            {
                throw new ArgumentException(@$ "{nameof(options.BatchSize)} {options.BatchSize} cannon be less than 1",
                                            $"{nameof(options)}");
            }

            cancellationToken.ThrowIfCancellationRequested();

            var documentType = options.DocumentType;

            // each Search Engine implementation has its own way of handing index rebuild
            if (options.DeleteExistingIndex)
            {
                progressCallback?.Invoke(new IndexingProgress($"{documentType}: deleting index", documentType));
                await _searchProvider.DeleteIndexAsync(documentType);
            }

            var configs = _configs.Where(c => c.DocumentType.EqualsInvariant(documentType)).ToArray();

            foreach (var config in configs)
            {
                await ProcessConfigurationAsync(config, options, progressCallback, cancellationToken);
            }
        }