Пример #1
0
        private MethodInfo GetProductPropertySetter(CatalogProduct product, Property property)
        {
            var name = property.Name;

            if (_productProperties.TryGetValue(name, out var result))
            {
                return(result);
            }

            var productType     = product.GetType();
            var productProperty = productType.GetProperty(name);

            result = productProperty?.GetSetMethod();

            _productProperties.Add(name, result);

            return(result);
        }
Пример #2
0
        protected virtual IndexDocument CreateDocument(CatalogProduct product)
        {
            var document = new IndexDocument(product.Id);

            document.Add(new IndexDocumentField("__type", product.GetType().Name)
            {
                IsRetrievable = true, IsFilterable = true
            });
            document.Add(new IndexDocumentField("__sort", product.Name)
            {
                IsRetrievable = true, IsFilterable = true
            });

            var statusField = product.IsActive != true || product.MainProductId != null ? "hidden" : "visible";

            IndexIsProperty(document, statusField);
            IndexIsProperty(document, string.IsNullOrEmpty(product.MainProductId) ? "product" : "variation");
            IndexIsProperty(document, product.Code);


            document.Add(new IndexDocumentField("status", statusField)
            {
                IsRetrievable = true, IsFilterable = true
            });
            document.Add(new IndexDocumentField("code", product.Code)
            {
                IsRetrievable = true, IsFilterable = true, IsCollection = true
            });
            document.Add(new IndexDocumentField("name", product.Name)
            {
                IsRetrievable = true, IsFilterable = true
            });
            document.Add(new IndexDocumentField("startdate", product.StartDate)
            {
                IsRetrievable = true, IsFilterable = true
            });
            document.Add(new IndexDocumentField("enddate", product.EndDate ?? DateTime.MaxValue)
            {
                IsRetrievable = true, IsFilterable = true
            });
            document.Add(new IndexDocumentField("createddate", product.CreatedDate)
            {
                IsRetrievable = true, IsFilterable = true
            });
            document.Add(new IndexDocumentField("lastmodifieddate", product.ModifiedDate ?? DateTime.MaxValue)
            {
                IsRetrievable = true, IsFilterable = true
            });
            document.Add(new IndexDocumentField("modifieddate", product.ModifiedDate ?? DateTime.MaxValue)
            {
                IsRetrievable = true, IsFilterable = true
            });
            document.Add(new IndexDocumentField("priority", product.Priority)
            {
                IsRetrievable = true, IsFilterable = true
            });
            document.Add(new IndexDocumentField("vendor", product.Vendor ?? "")
            {
                IsRetrievable = true, IsFilterable = true
            });
            document.Add(new IndexDocumentField("productType", product.ProductType ?? "")
            {
                IsRetrievable = true, IsFilterable = true
            });
            document.Add(new IndexDocumentField("mainProductId", product.MainProductId ?? "")
            {
                IsRetrievable = true, IsFilterable = true
            });

            // Add priority in virtual categories to search index
            if (product.Links != null)
            {
                foreach (var link in product.Links)
                {
                    document.Add(new IndexDocumentField($"priority_{link.CatalogId}_{link.CategoryId}", link.Priority)
                    {
                        IsRetrievable = true, IsFilterable = true
                    });
                }
            }

            // Add catalogs to search index
            var catalogs = product.Outlines
                           .Select(o => o.Items.First().Id)
                           .Distinct(StringComparer.OrdinalIgnoreCase)
                           .ToArray();

            foreach (var catalogId in catalogs)
            {
                document.Add(new IndexDocumentField("catalog", catalogId.ToLowerInvariant())
                {
                    IsRetrievable = true, IsFilterable = true, IsCollection = true
                });
            }

            // Add outlines to search index
            var outlineStrings = GetOutlineStrings(product.Outlines);

            foreach (var outline in outlineStrings)
            {
                document.Add(new IndexDocumentField("__outline", outline.ToLowerInvariant())
                {
                    IsRetrievable = true, IsFilterable = true, IsCollection = true
                });
            }

            // Types of properties which values should be added to the searchable __content field
            var contentPropertyTypes = new[] { PropertyType.Product, PropertyType.Variation };

            // Index custom product properties
            IndexCustomProperties(document, product.Properties, product.PropertyValues, contentPropertyTypes);

            //Index product category properties
            if (product.Category != null)
            {
                IndexCustomProperties(document, product.Category.Properties, product.Category.PropertyValues, contentPropertyTypes);
            }

            //Index catalog properties
            if (product.Catalog != null)
            {
                IndexCustomProperties(document, product.Catalog.Properties, product.Catalog.PropertyValues, contentPropertyTypes);
            }

            if (product.Variations != null)
            {
                if (product.Variations.Any(c => c.ProductType == "Physical"))
                {
                    document.Add(new IndexDocumentField("type", "physical")
                    {
                        IsRetrievable = true, IsFilterable = true, IsCollection = true
                    });
                    IndexIsProperty(document, "physical");
                }

                if (product.Variations.Any(c => c.ProductType == "Digital"))
                {
                    document.Add(new IndexDocumentField("type", "digital")
                    {
                        IsRetrievable = true, IsFilterable = true, IsCollection = true
                    });
                    IndexIsProperty(document, "digital");
                }

                foreach (var variation in product.Variations)
                {
                    document.Add(new IndexDocumentField("code", variation.Code)
                    {
                        IsRetrievable = true, IsFilterable = true, IsCollection = true
                    });
                    // add the variation code to content
                    document.Add(new IndexDocumentField("__content", variation.Code)
                    {
                        IsRetrievable = true, IsSearchable = true, IsCollection = true
                    });
                    IndexCustomProperties(document, variation.Properties, variation.PropertyValues, contentPropertyTypes);
                }
            }

            // add to content
            document.Add(new IndexDocumentField("__content", product.Name)
            {
                IsRetrievable = true, IsSearchable = true, IsCollection = true
            });
            document.Add(new IndexDocumentField("__content", product.Code)
            {
                IsRetrievable = true, IsSearchable = true, IsCollection = true
            });

            if (StoreObjectsInIndex)
            {
                // Index serialized product
                var itemDto = product.ToWebModel(_blobUrlResolver);
                document.AddObjectFieldValue(itemDto);
            }

            return(document);
        }
Пример #3
0
        protected virtual IndexDocument CreateDocument(CatalogProduct product)
        {
            var document = new IndexDocument(product.Id);

            document.AddFilterableValue("__type", product.GetType().Name);
            document.AddFilterableValue("__sort", product.Name);

            var statusField = product.IsActive != true || product.MainProductId != null ? "hidden" : "visible";

            IndexIsProperty(document, statusField);
            IndexIsProperty(document, string.IsNullOrEmpty(product.MainProductId) ? "product" : "variation");
            IndexIsProperty(document, product.Code);

            document.AddFilterableValue("status", statusField);
            document.AddFilterableAndSearchableValue("sku", product.Code);
            document.AddFilterableAndSearchableValue("code", product.Code);// { IsRetrievable = true, IsFilterable = true, IsCollection = true });
            document.AddFilterableAndSearchableValue("name", product.Name);
            document.AddFilterableValue("startdate", product.StartDate);
            document.AddFilterableValue("enddate", product.EndDate ?? DateTime.MaxValue);
            document.AddFilterableValue("createddate", product.CreatedDate);
            document.AddFilterableValue("lastmodifieddate", product.ModifiedDate ?? DateTime.MaxValue);
            document.AddFilterableValue("modifieddate", product.ModifiedDate ?? DateTime.MaxValue);
            document.AddFilterableValue("priority", product.Priority);
            document.AddFilterableValue("vendor", product.Vendor ?? "");
            document.AddFilterableValue("productType", product.ProductType ?? "");
            document.AddFilterableValue("mainProductId", product.MainProductId ?? "");

            // Add priority in virtual categories to search index
            if (product.Links != null)
            {
                foreach (var link in product.Links)
                {
                    document.AddFilterableValue($"priority_{link.CatalogId}_{link.CategoryId}", link.Priority);
                }
            }

            // Add catalogs to search index
            var catalogs = product.Outlines
                           .Select(o => o.Items.First().Id)
                           .Distinct(StringComparer.OrdinalIgnoreCase)
                           .ToArray();

            document.AddFilterableValues("catalog", catalogs);

            // Add outlines to search index
            var outlineStrings = GetOutlineStrings(product.Outlines);

            document.AddFilterableValues("__outline", outlineStrings);

            document.AddFilterableValues("__outline_named", GetOutlineStrings(product.Outlines, getNameLatestItem: true));

            // Add the all physical and virtual paths
            document.AddFilterableValues("__path", product.Outlines.Select(x => string.Join("/", x.Items.Take(x.Items.Count - 1).Select(i => i.Id))).ToList());

            // Types of properties which values should be added to the searchable __content field
            var contentPropertyTypes = new[] { PropertyType.Product, PropertyType.Variation };

            // Index custom product properties
            IndexCustomProperties(document, product.Properties, contentPropertyTypes);

            //Index product category properties
            if (product.Category != null)
            {
                IndexCustomProperties(document, product.Category.Properties, contentPropertyTypes);
            }

            //Index catalog properties
            if (product.Catalog != null)
            {
                IndexCustomProperties(document, product.Catalog.Properties, contentPropertyTypes);
            }

            if (StoreObjectsInIndex)
            {
                // Index serialized product
                document.AddObjectFieldValue(product);
            }

            return(document);
        }
Пример #4
0
        protected virtual bool IndexItem(ResultDocument doc, CatalogProduct item, Price[] prices)
        {
            var indexStoreNotAnalyzed = new[] { IndexStore.Yes, IndexType.NotAnalyzed };
            var indexStoreNotAnalyzedStringCollection = new[] { IndexStore.Yes, IndexType.NotAnalyzed, IndexDataType.StringCollection };
            var indexStoreAnalyzedStringCollection    = new[] { IndexStore.Yes, IndexType.Analyzed, IndexDataType.StringCollection };

            doc.Add(new DocumentField("__key", item.Id.ToLower(), indexStoreNotAnalyzed));
            doc.Add(new DocumentField("__type", item.GetType().Name, indexStoreNotAnalyzed));
            doc.Add(new DocumentField("__sort", item.Name, indexStoreNotAnalyzed));
            IndexIsProperty(doc, "product");
            var statusField = (item.IsActive != true || item.MainProductId != null) ? "hidden" : "visible";

            IndexIsProperty(doc, statusField);
            doc.Add(new DocumentField("status", statusField, indexStoreNotAnalyzed));
            doc.Add(new DocumentField("code", item.Code, indexStoreNotAnalyzed));
            IndexIsProperty(doc, item.Code);
            doc.Add(new DocumentField("name", item.Name, indexStoreNotAnalyzed));
            doc.Add(new DocumentField("startdate", item.StartDate, indexStoreNotAnalyzed));
            doc.Add(new DocumentField("enddate", item.EndDate.HasValue ? item.EndDate : DateTime.MaxValue, indexStoreNotAnalyzed));
            doc.Add(new DocumentField("createddate", item.CreatedDate, indexStoreNotAnalyzed));
            doc.Add(new DocumentField("lastmodifieddate", item.ModifiedDate ?? DateTime.MaxValue, indexStoreNotAnalyzed));
            doc.Add(new DocumentField("priority", item.Priority, indexStoreNotAnalyzed));
            doc.Add(new DocumentField("vendor", item.Vendor ?? "", indexStoreNotAnalyzed));
            doc.Add(new DocumentField("lastindexdate", DateTime.UtcNow, indexStoreNotAnalyzed));

            // Add priority in virtual categories to search index
            foreach (var link in item.Links)
            {
                doc.Add(new DocumentField(string.Format(CultureInfo.InvariantCulture, "priority_{0}_{1}", link.CatalogId, link.CategoryId), link.Priority, indexStoreNotAnalyzed));
            }

            // Add catalogs to search index
            var catalogs = item.Outlines
                           .Select(o => o.Items.First().Id)
                           .Distinct(StringComparer.OrdinalIgnoreCase)
                           .ToArray();

            foreach (var catalogId in catalogs)
            {
                doc.Add(new DocumentField("catalog", catalogId.ToLower(), indexStoreNotAnalyzedStringCollection));
            }

            // Add outlines to search index
            var outlineStrings = GetOutlineStrings(item.Outlines);

            foreach (var outline in outlineStrings)
            {
                doc.Add(new DocumentField("__outline", outline.ToLower(), indexStoreNotAnalyzedStringCollection));
            }

            // Index custom properties
            IndexItemCustomProperties(doc, item);

            if (item.Variations != null)
            {
                if (item.Variations.Any(c => c.ProductType == "Physical"))
                {
                    doc.Add(new DocumentField("type", "physical", new[] { IndexStore.Yes, IndexType.NotAnalyzed, IndexDataType.StringCollection }));
                    IndexIsProperty(doc, "physical");
                }

                if (item.Variations.Any(c => c.ProductType == "Digital"))
                {
                    doc.Add(new DocumentField("type", "digital", new[] { IndexStore.Yes, IndexType.NotAnalyzed, IndexDataType.StringCollection }));
                    IndexIsProperty(doc, "digital");
                }

                foreach (var variation in item.Variations)
                {
                    IndexItemCustomProperties(doc, variation);
                }
            }

            IndexItemPrices(doc, prices, item);

            // add to content
            doc.Add(new DocumentField("__content", item.Name, indexStoreAnalyzedStringCollection));
            doc.Add(new DocumentField("__content", item.Code, indexStoreAnalyzedStringCollection));

            return(true);
        }