Example #1
0
        protected virtual async Task <IList <IndexDocument> > GetDocumentsAsync(IList <string> documentIds, IIndexDocumentBuilder primaryDocumentBuilder, IEnumerable <IIndexDocumentBuilder> secondaryDocumentBuilders, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var primaryDocuments = (await primaryDocumentBuilder.GetDocumentsAsync(documentIds))
                                   ?.Where(d => d != null)
                                   .ToList();

            if (primaryDocuments?.Any() == true)
            {
                if (secondaryDocumentBuilders != null)
                {
                    var primaryDocumentIds = primaryDocuments.Select(d => d.Id).ToArray();
                    var secondaryDocuments = await GetSecondaryDocumentsAsync(secondaryDocumentBuilders, primaryDocumentIds, cancellationToken);

                    MergeDocuments(primaryDocuments, secondaryDocuments);
                }

                // Add system fields
                foreach (var document in primaryDocuments)
                {
                    document.Add(new IndexDocumentField(KnownDocumentFields.IndexationDate, DateTime.UtcNow)
                    {
                        IsRetrievable = true,
                        IsFilterable  = true
                    });
                }
            }

            return(primaryDocuments);
        }