Exemplo n.º 1
0
        public async ValueTask <FluidValue> ProcessAsync(FluidValue input, FilterArguments arguments, LiquidTemplateContext ctx)
        {
            if (input.Type == FluidValues.Array)
            {
                var contentItems = new List <ContentItem>();
                foreach (var objValue in input.Enumerate())
                {
                    var contentItem = GetContentItem(objValue);
                    if (contentItem != null)
                    {
                        if (!_fullTextRecursionHelper.IsRecursive(contentItem))
                        {
                            contentItems.Add(contentItem);
                        }
                    }
                }

                if (!contentItems.Any())
                {
                    return(NilValue.Instance);
                }

                var aspects = new List <FullTextAspect>();

                foreach (var contentItem in contentItems)
                {
                    aspects.Add(await _contentManager.PopulateAspectAsync <FullTextAspect>(contentItem));
                }

                // When returning segments seperate them so multiple segments are indexed individually.
                return(new ArrayValue(aspects.SelectMany(x => x.Segments).Where(x => !String.IsNullOrEmpty(x)).Select(x => new StringValue(x + ' '))));
            }
            else
            {
                var contentItem = GetContentItem(input);

                if (contentItem == null || _fullTextRecursionHelper.IsRecursive(contentItem))
                {
                    return(NilValue.Instance);
                }

                var fullTextAspect = await _contentManager.PopulateAspectAsync <FullTextAspect>(contentItem);

                // Remove empty strings as display text is often unused in contained content items.
                return(new ArrayValue(fullTextAspect.Segments.Where(x => !String.IsNullOrEmpty(x)).Select(x => new StringValue(x))));
            }
        }