protected virtual IndexDocument CreateDocument(Category category)
        {
            var document = new IndexDocument(category.Id);

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

            var statusField = category.IsActive != true ? "hidden" : "visible";

            IndexIsProperty(document, statusField);
            IndexIsProperty(document, "category");
            IndexIsProperty(document, category.Code);

            document.Add(new IndexDocumentField("status", statusField)
            {
                IsRetrievable = true, IsFilterable = true
            });
            document.Add(new IndexDocumentField("code", category.Code)
            {
                IsRetrievable = true, IsFilterable = true
            });
            document.Add(new IndexDocumentField("name", category.Name)
            {
                IsRetrievable = true, IsFilterable = true
            });
            document.Add(new IndexDocumentField("createddate", category.CreatedDate)
            {
                IsRetrievable = true, IsFilterable = true
            });
            document.Add(new IndexDocumentField("lastmodifieddate", category.ModifiedDate ?? DateTime.MaxValue)
            {
                IsRetrievable = true, IsFilterable = true
            });
            document.Add(new IndexDocumentField("modifieddate", category.ModifiedDate ?? DateTime.MaxValue)
            {
                IsRetrievable = true, IsFilterable = true
            });
            document.Add(new IndexDocumentField("priority", category.Priority)
            {
                IsRetrievable = true, IsFilterable = true
            });

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

            // Add catalogs to search index
            var catalogs = category.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(category.Outlines);

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

            foreach (var outlineItem in GetOutlineStrings(category.Outlines, getNameLatestItem: true))
            {
                document.Add(new IndexDocumentField($"__outline_named", outlineItem)
                {
                    IsRetrievable = true, IsFilterable = true, IsCollection = true
                });
            }

            IndexCustomProperties(document, category.Properties, new[] { PropertyType.Category });

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

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

            document.Add(new IndexDocumentField("parent", category.ParentId ?? category.CatalogId)
            {
                IsRetrievable = true, IsSearchable = true, IsFilterable = true
            });

            return(document);
        }
Example #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);
        }
Example #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);
        }