Ejemplo n.º 1
0
        /// <summary>
        /// Writes additional IContent information to stream
        /// </summary>
        /// <param name="args"></param>
        public virtual void ProcessContent(IVulcanIndexingModifierArgs args)
        {
            // index ancestors
            var ancestors = new List <ContentReference>();

            if (_vulcanContentAncestorLoaders?.Any() == true)
            {
                foreach (var ancestorLoader in _vulcanContentAncestorLoaders)
                {
                    var ancestorsFound = ancestorLoader.GetAncestors(args.Content)?.ToList();

                    if (ancestorsFound?.Any() == true)
                    {
                        ancestors.AddRange(ancestorsFound);
                    }
                }
            }

            args.AdditionalItems[VulcanFieldConstants.Ancestors] = ancestors.Select(x => x.ToReferenceWithoutVersion()).Distinct();

            // index read permission
            var permissions = _contentSecurityDescriptor.Get(args.Content.ContentLink);

            if (permissions != null) // will be null for commerce products, compatibility handled in commerce modifier
            {
                args.AdditionalItems[VulcanFieldConstants.ReadPermission] = permissions.Entries.
                                                                            Where(x =>
                                                                                  x.Access.HasFlag(AccessLevel.Read) ||
                                                                                  x.Access.HasFlag(AccessLevel.Administer) ||
                                                                                  x.Access.HasFlag(AccessLevel.FullAccess)).Select(x => x.Name);
            }

            // index VulcanSearchableAttribute
            var contents   = new List <string>();
            var properties = args.Content.GetType().GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(VulcanSearchableAttribute)));

            foreach (var p in properties)
            {
                var value = p.GetValue(args.Content);

                // Property to string conversions
                if (p.PropertyType == typeof(ContentArea))
                {
                    value = (value as ContentArea).GetContentAreaContents();
                }

                var v = value?.ToString();

                if (!string.IsNullOrWhiteSpace(v))
                {
                    contents.Add(v);
                }
            }

            args.AdditionalItems[VulcanFieldConstants.CustomContents] = string.Join(" ", contents);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds attachment content to serialized data
        /// </summary>
        /// <param name="args"></param>
        public void ProcessContent(IVulcanIndexingModifierArgs args)
        {
            if (!IsMediaReadable(args, out var isPipeline, out var media))
            {
                return;
            }
            var mediaBytes     = _mediaReader.ReadToEnd(media);
            var base64Contents = Convert.ToBase64String(mediaBytes);
            var mimeType       = media.MimeType;

            var stringContents = _byteConvertor.ConvertToString(mediaBytes, mimeType);

            if (!string.IsNullOrWhiteSpace(stringContents))
            {
                args.AdditionalItems[MediaStringContents] = stringContents;
            }

            if (!isPipeline)
            {
                return;
            }

#if NEST2
            var mediaFields = new Dictionary <string, object>
            {
                ["_name"]           = media.Name,
                ["_indexed_chars"]  = -1,// indexes entire document instead of first 100000 chars
                ["_content_type"]   = mimeType,
                ["_content_length"] = mediaBytes.LongLength,
                ["_content"]        = base64Contents
            };

            args.AdditionalItems[MediaContents] = mediaFields;
#elif NEST5
            // 5x: only send base64 content if pipeline is enabled
            args.AdditionalItems[MediaContents] = base64Contents;
#endif
        }
Ejemplo n.º 3
0
        private bool IsMediaReadable(IVulcanIndexingModifierArgs args, out bool isPipeline, out MediaData media)
        {
            media      = args.Content as MediaData;
            isPipeline = false;

            if (media == null)
            {
                return(false);
            }

            if (_attachmentPipeline == null)
            {
                _attachmentPipeline = _vulcanPipelineSelector.GetPipelineById(Implementation.VulcanAttachmentPipelineInstaller.PipelineId);
            }

#if NEST2
            // for 2x, have to evaluate pipeline here
            if (_attachmentPipeline?.IsMatch(args.Content) == true)
            {
                return(isPipeline = true);
            }
#endif

            if (args.PipelineId == Implementation.VulcanAttachmentPipelineInstaller.PipelineId)
            {
                return(isPipeline = true);
            }

            if (_converterType == null)
            {
                _converterType = _byteConvertor.GetType();
            }

            // default converter does nothing so don't read it
            return(_converterType != typeof(DefaultVulcanBytesToStringConverter));
        }
Ejemplo n.º 4
0
        public void ProcessContent(IVulcanIndexingModifierArgs args)
        {
            switch (args.Content)
            {
            case VariationContent variationContent:

                var marketPrices = GetDefaultPrices(variationContent);
                var prices       = new Dictionary <string, decimal>();

                if (marketPrices?.Any() == true)
                {
                    foreach (var market in marketPrices)
                    {
                        foreach (var price in market.Value)
                        {
                            prices[market.Key + "_" + price.Key] = price.Value;
                        }
                    }
                }

                if (prices.Any())
                {
                    args.AdditionalItems["__prices"] = prices;
                }
                break;

            case ProductContent productContent:
                var pricesLow  = new Dictionary <string, Dictionary <string, decimal> >();
                var pricesHigh = new Dictionary <string, Dictionary <string, decimal> >();
                var variants   = _contentLoader.GetItems(productContent.GetVariants(), productContent.Language);

                if (variants != null)
                {
                    foreach (var v in variants)
                    {
                        if (!(v is VariationContent variant))
                        {
                            continue;
                        }
                        var markets = GetDefaultPrices(variant);

                        if (markets == null)
                        {
                            continue;
                        }

                        foreach (var market in markets)
                        {
                            if (!pricesLow.ContainsKey(market.Key))
                            {
                                pricesLow.Add(market.Key, new Dictionary <string, decimal>());
                            }

                            if (!pricesHigh.ContainsKey(market.Key))
                            {
                                pricesHigh.Add(market.Key, new Dictionary <string, decimal>());
                            }

                            if (!market.Value.Any())
                            {
                                continue;
                            }

                            foreach (var price in market.Value)
                            {
                                if (!pricesLow[market.Key].ContainsKey(price.Key))
                                {
                                    pricesLow[market.Key].Add(price.Key, price.Value);
                                }
                                else
                                {
                                    if (price.Value < pricesLow[market.Key][price.Key])
                                    {
                                        pricesLow[market.Key][price.Key] = price.Value;
                                    }
                                }

                                if (!pricesHigh[market.Key].ContainsKey(price.Key))
                                {
                                    pricesHigh[market.Key].Add(price.Key, price.Value);
                                }
                                else
                                {
                                    if (price.Value > pricesHigh[market.Key][price.Key])
                                    {
                                        pricesHigh[market.Key][price.Key] = price.Value;
                                    }
                                }
                            }
                        }
                    }
                }

                var flatPricesLow  = new Dictionary <string, decimal>();
                var flatPricesHigh = new Dictionary <string, decimal>();

                if (pricesLow.Any())
                {
                    foreach (var market in pricesLow)
                    {
                        foreach (var price in market.Value)
                        {
                            flatPricesLow[market.Key + "_" + price.Key] = price.Value;
                        }
                    }
                }
                if (pricesHigh.Any())
                {
                    foreach (var market in pricesHigh)
                    {
                        foreach (var price in market.Value)
                        {
                            flatPricesHigh[market.Key + "_" + price.Key] = price.Value;
                        }
                    }
                }

                if (flatPricesLow.Any())
                {
                    args.AdditionalItems["__pricesLow"] = flatPricesLow;
                }
                if (flatPricesHigh.Any())
                {
                    args.AdditionalItems["__pricesHigh"] = flatPricesHigh;
                }

                break;
            }

            // read permission compatibility for commerce content, since markets handle access
            var commercePermissionEntries = new[]
            {
                new AccessControlEntry(EveryoneRole.RoleName, AccessLevel.Read),
                new AccessControlEntry(AnonymousRole.RoleName, AccessLevel.Read)
            };

            args.AdditionalItems[VulcanFieldConstants.ReadPermission] = commercePermissionEntries.Select(x => x.Name);
            //streamWriter.Write(",\"" + VulcanFieldConstants.ReadPermission + "\":[");
            //streamWriter.Write(string.Join(",", commercePermissionEntries.Select(x => "\"" + x.Name + "\"")));
            //streamWriter.Write("]");

            //streamWriter.Flush();
        }