コード例 #1
0
        protected override async Task <IEnumerable <IDocument> > ExecuteInputAsync(IDocument input, IExecutionContext context)
        {
            IEnumerable <IEnumerable <string> > records;

            using (Stream stream = input.GetContentStream())
            {
                records = ExcelFile.GetAllRecords(stream);
            }

            using (Stream contentStream = await context.GetContentStreamAsync())
            {
                CsvFile.WriteAllRecords(records, contentStream);
                return(input.Clone(context.GetContentProvider(contentStream, MediaTypes.Get(".csv"))).Yield());
            }
        }
コード例 #2
0
        /// <inheritdoc />
        protected override async Task <IEnumerable <IDocument> > ExecuteContextAsync(IExecutionContext context)
        {
            ILunrIndexItem[] searchIndexItems =
                await context.Inputs
                .ToAsyncEnumerable()
                .SelectAwait(async x => await _searchIndexItem.GetValueAsync(x, context))
                .Where(x => !string.IsNullOrEmpty(x?.Title) && !string.IsNullOrEmpty(x.Content))
                .ToArrayAsync();

            if (searchIndexItems.Length == 0)
            {
                context.LogWarning("It's not possible to build the search index because no documents contain the necessary metadata.");
                return(Array.Empty <IDocument>());
            }

            string[] stopwords = await GetStopwordsAsync(context);

            StringBuilder scriptBuilder = BuildScript(searchIndexItems, stopwords, context);
            string        script        = _script(scriptBuilder, context);

            return(context.CreateDocument(_destination, await context.GetContentProviderAsync(script, MediaTypes.Get(".js"))).Yield());
        }