Exemple #1
0
        public override object ComputeFieldValue(IIndexable indexable)
        {
            var item = (Item)(indexable as SitecoreIndexableItem);

            if (item == null)
            {
                return(null);
            }

            var indexableRenderingArgs = new IndexableRenderingsArgs(item);

            CorePipeline.Run("indexing.getIndexableRenderings", indexableRenderingArgs);

            if (!indexableRenderingArgs.ValidRenderingIds.Any())
            {
                return(null);
            }

            var deviceItem = item.Database.Resources.Devices.GetAll().FirstOrDefault(d => d.IsDefault);

            if (deviceItem == null)
            {
                return(null);
            }

            var extractRenderingsDatasourceArgs = new ExtractRenderingsDatasourceArgs(item, indexableRenderingArgs.ValidRenderingIds, deviceItem);

            CorePipeline.Run("indexing.extractRenderingsDatasources", extractRenderingsDatasourceArgs);

            if (!extractRenderingsDatasourceArgs.DatasourceItems.Any())
            {
                return(null);
            }

            extractRenderingsDatasourceArgs.DatasourceItems = extractRenderingsDatasourceArgs.DatasourceItems.DistinctBy(i => i.ID).ToList();

            var content = new List <string>();

            foreach (var itemDatasource in extractRenderingsDatasourceArgs.DatasourceItems)
            {
                var getDatasourceContentArgs = new GetDatasourceContentArgs(itemDatasource, content, item);

                CorePipeline.Run("indexing.getDatasourceContent", getDatasourceContentArgs);
            }

            if (!content.Any())
            {
                return(null);
            }

            var aggregateContent = content.Aggregate((a, b) => $"{a} {b}");

            var renderedContentStringArgs = new RenderedContentStringArgs(item, aggregateContent);

            CorePipeline.Run("indexing.renderedContent.Saving", renderedContentStringArgs);

            return(renderedContentStringArgs.RenderedContent);
        }
        public void Process(ExtractRenderingsDatasourceArgs args)
        {
            if (string.IsNullOrWhiteSpace(FieldId) || !ID.IsID(FieldId))
            {
                return;
            }

            var fieldId = new ID(FieldId);

            var layoutField = args.IndexedItem.Fields[fieldId];

            var layoutXml = LayoutField.GetFieldValue(layoutField);

            if (string.IsNullOrEmpty(layoutXml))
            {
                return;
            }

            var renderings = args.IndexedItem.Visualization.GetRenderings(args.DeviceItem, false);

            if (renderings == null || renderings.Length == 0)
            {
                return;
            }

            for (var renderingIndex = renderings.Length - 1; renderingIndex >= 0; renderingIndex--)
            {
                var rendering = renderings[renderingIndex];

                if (rendering == null || rendering.Database != args.IndexedItem.Database)
                {
                    continue;
                }

                if (!args.IndexableRenderingIds.Contains(rendering.RenderingID))
                {
                    continue;
                }

                var datasourceId = rendering.Settings.DataSource;

                if (!ID.IsID(datasourceId))
                {
                    continue;
                }

                var datasourceItem = GetDatasourceWithFallback(args.IndexedItem.Database, new ID(datasourceId), args.IndexedItem.Language);

                if (datasourceItem == null || datasourceItem.Versions.Count == 0)
                {
                    continue;
                }

                args.DatasourceItems.Add(datasourceItem);
            }
        }