protected virtual void IndexItem(ref ResultDocument doc, string productId) { var item = _itemService.GetById(productId, ItemResponseGroup.ItemProperties | ItemResponseGroup.Categories); doc.Add(new DocumentField("__key", item.Id.ToLower(), new[] { IndexStore.Yes, IndexType.NotAnalyzed })); //doc.Add(new DocumentField("__loc", "en-us", new[] { IndexStore.YES, IndexType.NOT_ANALYZED })); doc.Add(new DocumentField("__type", item.GetType().Name, new[] { IndexStore.Yes, IndexType.NotAnalyzed })); doc.Add(new DocumentField("__sort", item.Name, new[] { IndexStore.Yes, IndexType.NotAnalyzed })); doc.Add(new DocumentField("__hidden", (!item.IsActive.Value || item.MainProductId != null).ToString().ToLower(), new[] { IndexStore.Yes, IndexType.NotAnalyzed })); doc.Add(new DocumentField("code", item.Code, new[] { IndexStore.Yes, IndexType.NotAnalyzed })); doc.Add(new DocumentField("name", item.Name, new[] { IndexStore.Yes, IndexType.NotAnalyzed })); doc.Add(new DocumentField("startdate", item.StartDate, new[] { IndexStore.Yes, IndexType.NotAnalyzed })); doc.Add(new DocumentField("enddate", item.EndDate.HasValue ? item.EndDate : DateTime.MaxValue, new[] { IndexStore.Yes, IndexType.NotAnalyzed })); doc.Add(new DocumentField("createddate", item.CreatedDate, new[] { IndexStore.Yes, IndexType.NotAnalyzed })); doc.Add(new DocumentField("lastmodifieddate", item.ModifiedDate ?? DateTime.MaxValue, new[] { IndexStore.Yes, IndexType.NotAnalyzed })); doc.Add(new DocumentField("catalog", item.CatalogId.ToLower(), new[] { IndexStore.Yes, IndexType.NotAnalyzed, IndexDataType.StringCollection })); doc.Add(new DocumentField("__outline", item.CatalogId.ToLower(), new[] { IndexStore.Yes, IndexType.NotAnalyzed, IndexDataType.StringCollection })); var outlines = new List <string>(); if (item.CategoryId != null) { outlines.AddRange(_catalogOutlineBuilder.GetOutlines(item.CategoryId)); } //Index item direct categories links if (item.Links != null) { foreach (var link in item.Links) { if (link.CategoryId != null) { outlines.AddRange(_catalogOutlineBuilder.GetOutlines(link.CategoryId)); //doc.Add(new DocumentField(string.Format("sort{0}{1}", link.CatalogId, link.CategoryId), category.Priority, new[] { IndexStore.Yes, IndexType.NotAnalyzed })); } } //Add outlines to search index foreach (var outline in outlines.Distinct()) { doc.Add(new DocumentField("__outline", outline.ToLower(), new[] { IndexStore.Yes, IndexType.NotAnalyzed })); } //Add all linked catalogs to search index foreach (var catalogId in outlines.Select(x => x.Split('/').FirstOrDefault()).Where(x => x != null).Distinct()) { doc.Add(new DocumentField("catalog", catalogId.ToLower(), new[] { IndexStore.Yes, IndexType.NotAnalyzed })); } } // Index custom properties IndexItemCustomProperties(ref doc, item); // Index item prices IndexItemPrices(ref doc, item); //Index item reviews //IndexReviews(ref doc, item); // add to content doc.Add(new DocumentField("__content", item.Name, new[] { IndexStore.Yes, IndexType.Analyzed, IndexDataType.StringCollection })); doc.Add(new DocumentField("__content", item.Code, new[] { IndexStore.Yes, IndexType.Analyzed, IndexDataType.StringCollection })); }
protected virtual void IndexItem(ref ResultDocument doc, string productId) { var item = _itemService.GetById(productId, ItemResponseGroup.ItemProperties | ItemResponseGroup.Links | ItemResponseGroup.Variations); if (item == null) { return; } doc.Add(new DocumentField("__key", item.Id.ToLower(), new[] { IndexStore.Yes, IndexType.NotAnalyzed })); //doc.Add(new DocumentField("__loc", "en-us", new[] { IndexStore.YES, IndexType.NOT_ANALYZED })); doc.Add(new DocumentField("__type", item.GetType().Name, new[] { IndexStore.Yes, IndexType.NotAnalyzed })); doc.Add(new DocumentField("__sort", item.Name, new[] { IndexStore.Yes, IndexType.NotAnalyzed })); doc.Add(new DocumentField("__hidden", (item.IsActive != true || item.MainProductId != null).ToString().ToLower(), new[] { IndexStore.Yes, IndexType.NotAnalyzed })); doc.Add(new DocumentField("code", item.Code, new[] { IndexStore.Yes, IndexType.NotAnalyzed })); doc.Add(new DocumentField("name", item.Name, new[] { IndexStore.Yes, IndexType.NotAnalyzed })); doc.Add(new DocumentField("startdate", item.StartDate, new[] { IndexStore.Yes, IndexType.NotAnalyzed })); doc.Add(new DocumentField("enddate", item.EndDate.HasValue ? item.EndDate : DateTime.MaxValue, new[] { IndexStore.Yes, IndexType.NotAnalyzed })); doc.Add(new DocumentField("createddate", item.CreatedDate, new[] { IndexStore.Yes, IndexType.NotAnalyzed })); doc.Add(new DocumentField("lastmodifieddate", item.ModifiedDate ?? DateTime.MaxValue, new[] { IndexStore.Yes, IndexType.NotAnalyzed })); var catalogs = new List <string> { item.CatalogId }; var outlines = new List <string> { item.CatalogId }; if (item.CategoryId != null) { outlines.AddRange(_catalogOutlineBuilder.GetOutlines(item.CategoryId)); } // Index item direct categories links if (item.Links != null) { foreach (var link in item.Links.Where(link => link.CategoryId != null)) { outlines.AddRange(_catalogOutlineBuilder.GetOutlines(link.CategoryId)); } // Add all linked catalogs to search index catalogs.AddRange(outlines.Select(x => x.Split('/').FirstOrDefault()).Where(x => x != null).Distinct()); } var indexStoreNotAnalyzedStringCollection = new[] { IndexStore.Yes, IndexType.NotAnalyzed, IndexDataType.StringCollection }; // Add catalogs to search index foreach (var catalogId in catalogs.Distinct(StringComparer.OrdinalIgnoreCase)) { doc.Add(new DocumentField("catalog", catalogId.ToLower(), indexStoreNotAnalyzedStringCollection)); } // Add outlines to search index foreach (var outline in outlines.Distinct(StringComparer.OrdinalIgnoreCase)) { doc.Add(new DocumentField("__outline", outline.ToLower(), indexStoreNotAnalyzedStringCollection)); } // Index custom properties IndexItemCustomProperties(ref doc, item); if (item.Variations != null) { if (item.Variations.Any(c => c.ProductType == "Physical")) { doc.Add(new DocumentField("producttype", "Physical", new[] { IndexStore.Yes, IndexType.NotAnalyzed, IndexDataType.StringCollection })); } if (item.Variations.Any(c => c.ProductType == "Digital")) { doc.Add(new DocumentField("producttype", "Digital", new[] { IndexStore.Yes, IndexType.NotAnalyzed, IndexDataType.StringCollection })); } foreach (var variation in item.Variations) { IndexItemCustomProperties(ref doc, variation); } } // Index item prices IndexItemPrices(ref doc, item); //Index item reviews //IndexReviews(ref doc, item); // add to content doc.Add(new DocumentField("__content", item.Name, new[] { IndexStore.Yes, IndexType.Analyzed, IndexDataType.StringCollection })); doc.Add(new DocumentField("__content", item.Code, new[] { IndexStore.Yes, IndexType.Analyzed, IndexDataType.StringCollection })); }