예제 #1
0
        public virtual async Task <IndexingResult> IndexDocumentsAsync(string documentType, string[] documentIds, IEnumerable <string> builderTypes = null)
        {
            // Todo: reuse general index api?
            var configs = _configs.Where(c => c.DocumentType.EqualsInvariant(documentType)).ToArray();
            var result  = new IndexingResult {
                Items = new List <IndexingResultItem>()
            };

            var partialUpdate = false;

            foreach (var config in configs)
            {
                var primaryDocumentBuilder = config.DocumentSource.DocumentBuilder;

                var additionalDocumentBuilders = config.RelatedSources?
                                                 .Where(s => s.DocumentBuilder != null)
                                                 .Select(s => s.DocumentBuilder)
                                                 .ToList() ?? new List <IIndexDocumentBuilder>();

                if ((builderTypes?.Any() ?? false) && additionalDocumentBuilders.Any() && _searchProvider is ISupportPartialUpdate)
                {
                    additionalDocumentBuilders = additionalDocumentBuilders.Where(x => builderTypes.Contains(x.GetType().FullName))
                                                 .ToList();

                    // In case of changing main object itself, there would be only primary document builder,
                    // but in the other cases, when changed additional dependent objects, primary builder should be nulled.
                    if (!builderTypes.Contains(primaryDocumentBuilder.GetType().FullName))
                    {
                        primaryDocumentBuilder = null;
                    }

                    partialUpdate = true;
                }

                var documents = await GetDocumentsAsync(documentIds, primaryDocumentBuilder, additionalDocumentBuilders, new CancellationTokenWrapper(CancellationToken.None));

                IndexingResult indexingResult;

                if (partialUpdate && _searchProvider is ISupportPartialUpdate supportPartialUpdateProvider)
                {
                    indexingResult = await supportPartialUpdateProvider.IndexPartialAsync(documentType, documents);
                }
                else
                {
                    indexingResult = await _searchProvider.IndexAsync(documentType, documents);
                }

                result.Items.AddRange(indexingResult.Items ?? Enumerable.Empty <IndexingResultItem>());
            }

            return(result);
        }
예제 #2
0
        protected virtual async Task <IndexingResult> IndexDocumentsAsync(string documentType, IList <string> documentIds, IIndexDocumentBuilder primaryDocumentBuilder, IEnumerable <IIndexDocumentBuilder> secondaryDocumentBuilders, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var documents = await GetDocumentsAsync(documentIds, primaryDocumentBuilder, secondaryDocumentBuilders, cancellationToken);

            var response = await _searchProvider.IndexAsync(documentType, documents);

            return(response);
        }