Exemplo n.º 1
0
        private void WalkCatalogNodes(ICatalogSystem catalogSystem, CatalogNodeDto nodes, CatalogDto.CatalogRow catalog, Dictionary <int, CatalogEntryDto.CatalogEntryRow> catalogEntryRows)
        {
            foreach (CatalogNodeDto.CatalogNodeRow node in nodes.CatalogNode)
            {
                CatalogSearchParameters pars    = new CatalogSearchParameters();
                CatalogSearchOptions    options = new CatalogSearchOptions {
                    CacheResults = false
                };
                pars.CatalogNames.Add(catalog.Name);
                pars.CatalogNodes.Add(node.Code);
                //CatalogEntryDto entries = CatalogContext.Current.FindItemsDto(
                //    pars,
                //    options,
                //    ref count,
                //    new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
                CatalogEntryDto entries = catalogSystem.GetCatalogEntriesDto(catalog.CatalogId, node.CatalogNodeId,
                                                                             new CatalogEntryResponseGroup(
                                                                                 CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo));

                _log.DebugFormat("Entries in Node: {0} (Count: {1})", node.Name, entries.CatalogEntry.Rows.Count);
                foreach (CatalogEntryDto.CatalogEntryRow entry in entries.CatalogEntry)
                {
                    // _log.DebugFormat("{3}: {0} ({1} - {2})", entry.Name, entry.Code, entry.CatalogEntryId, entry.ClassTypeId);
                    if (catalogEntryRows.ContainsKey(entry.CatalogEntryId) == false)
                    {
                        catalogEntryRows.Add(entry.CatalogEntryId, entry);
                    }
                }

                // Get Subnodes
                CatalogNodeDto subNodes = catalogSystem.GetCatalogNodesDto(catalog.CatalogId, node.CatalogNodeId);
                WalkCatalogNodes(catalogSystem, subNodes, catalog, catalogEntryRows);
            }
        }
Exemplo n.º 2
0
        public IEnumerable <CatalogEntryDto.VariationRow> GetVariations(int productId)
        {
            ICatalogSystem            catalog          = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance <ICatalogSystem>();
            CatalogEntryResponseGroup responseGroup    = new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull);
            CatalogEntryDto           variationEntries = catalog.GetCatalogEntriesDto(productId,
                                                                                      string.Empty,
                                                                                      string.Empty,
                                                                                      responseGroup);

            return(variationEntries.Variation.ToList());
        }
Exemplo n.º 3
0
        protected override void OnCatalogEntryIndex(ref SearchDocument document, Mediachase.Commerce.Catalog.Dto.CatalogEntryDto.CatalogEntryRow entry, string language)
        {
            if (entry != null && entry.ClassTypeId.Equals(EntryType.Product, StringComparison.InvariantCultureIgnoreCase))
            {
                if (!MetaDataContextClone.Language.Equals(language, StringComparison.InvariantCultureIgnoreCase))
                {
                    MetaDataContextClone.Language = language;
                }

                CatalogRelationDto relationDto = _catalog.GetCatalogRelationDto(0, 0, entry.CatalogEntryId, string.Empty,
                                                                                new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.CatalogEntry));

                if (relationDto != null && relationDto.CatalogEntryRelation != null && relationDto.CatalogEntryRelation.Count > 0)
                {
                    List <int> childIds = new List <int>();

                    foreach (CatalogRelationDto.CatalogEntryRelationRow relationRow in relationDto.CatalogEntryRelation)
                    {
                        childIds.Add(relationRow.ChildEntryId);
                    }

                    CatalogEntryDto skuDto = _catalog.GetCatalogEntriesDto(childIds.ToArray(),
                                                                           new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo));

                    List <string> searchProperties = new List <string>
                    {
                        SearchField.Store.NO,
                        SearchField.Index.TOKENIZED,
                        SearchField.IncludeInDefaultSearch.YES
                    };

                    List <string> colorVariations = new List <string>();
                    if (skuDto != null && skuDto.CatalogEntry != null && skuDto.CatalogEntry.Count > 0)
                    {
                        foreach (CatalogEntryDto.CatalogEntryRow row in skuDto.CatalogEntry)
                        {
                            Hashtable hash = ObjectHelper.GetMetaFieldValues(row);
                            if (hash.Contains("Color"))
                            {
                                string color = hash["Color"].ToString();
                                if (!string.IsNullOrEmpty(color) && !colorVariations.Contains(color.ToLower()))
                                {
                                    colorVariations.Add(color.ToLower());
                                    document.Add(new SearchField("Color", color.ToLower(), searchProperties.ToArray()));
                                    OnSearchIndexMessage(new Mediachase.Search.SearchIndexEventArgs(
                                                             $"The color {color} was added to the index for {entry.Name}.", 1));
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        private List <ProductInfo> BuildProductVariationRelations(Dictionary <int, CatalogEntryDto.CatalogEntryRow> catalogEntryRows, ICatalogSystem catalog)
        {
            List <ProductInfo>        productsAndVariations = new List <ProductInfo>();
            CatalogEntryResponseGroup variatonRespGroup     =
                new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo);

            // Build product -> variation hierarchy
            foreach (KeyValuePair <int, CatalogEntryDto.CatalogEntryRow> keyValue in catalogEntryRows)
            {
                CatalogEntryDto.CatalogEntryRow entryRow = keyValue.Value;
                if (string.Compare(entryRow.ClassTypeId, "Product", StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    ProductInfo productInfo = new ProductInfo
                    {
                        EntryRow       = entryRow,
                        CatalogEntryId = keyValue.Key,
                        Code           = entryRow.Code,
                        Name           = entryRow.Name
                    };

                    // Now load all related variations manually
                    CatalogEntryDto variationEntries = catalog.GetCatalogEntriesDto(keyValue.Key, string.Empty, string.Empty,
                                                                                    variatonRespGroup);

                    foreach (CatalogEntryDto.CatalogEntryRow variationRow in variationEntries.CatalogEntry)
                    {
                        if (catalogEntryRows.ContainsKey(variationRow.CatalogEntryId))
                        {
                            productInfo.Variations.Add(catalogEntryRows[variationRow.CatalogEntryId]);
                        }
                    }

                    // Only add if we have a product with one or more variations
                    if (productInfo.Variations.Count > 0)
                    {
                        productsAndVariations.Add(productInfo);
                    }
                }
            }
            return(productsAndVariations);
        }
Exemplo n.º 5
0
        public IEnumerable <CatalogEntryDto.VariationRow> GetVariations(string productCode)
        {
            ICatalogSystem catalog = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance <ICatalogSystem>();

            CatalogEntryDto product = Get(productCode);

            if (product.CatalogEntry != null && product.CatalogEntry.Rows.Count > 0)
            {
                CatalogEntryResponseGroup responseGroup = new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull);
                int productId = product.CatalogEntry[0].CatalogEntryId;
                // Need to call this overload due to a bug, which I cannot recall at the moment
                CatalogEntryDto variationEntries = catalog.GetCatalogEntriesDto(productId,
                                                                                string.Empty,
                                                                                string.Empty,
                                                                                responseGroup);

                // variationEntries.Variation[0]

                return(variationEntries.Variation.ToList());
            }
            return(null);
        }
Exemplo n.º 6
0
        public ActionResult ProviderModelQuery(string keyWord)
        {
            // Create criteria
            CatalogEntrySearchCriteria criteria = new CatalogEntrySearchCriteria
            {
                RecordsToRetrieve = 200, // there is a default of 50
                // Locale have to be there... else no hits
                Locale       = ContentLanguage.PreferredCulture.TwoLetterISOLanguageName,
                SearchPhrase = keyWord
            };

            // Add more to the criteria
            criteria.Sort = CatalogEntrySearchCriteria.DefaultSortOrder;
            criteria.CatalogNames.Add("Fashion"); // ...if we know what catalog to search in, not mandatory
            //criteria.IgnoreFilterOnLanguage = true; // if we want to search all languages... need the locale anyway

            criteria.ClassTypes.Add(EntryType.Variation);
            criteria.MarketId = MarketId.Default; // should use the ICurrentMarket service, of course...

            criteria.IsFuzzySearch      = true;
            criteria.FuzzyMinSimilarity = 0.7F;

            criteria.IncludeInactive = true;

            // the _outline field
            System.Collections.Specialized.StringCollection sc =
                new System.Collections.Specialized.StringCollection
            {
                "Fashion/Clothes_1/Men_1/Shirts_1",
                "Fashion/Clothes_1/UniSex_1"
            };
            criteria.Outlines = sc; // another "AND"

            #region SimpleWalues
            ///*
            // Add facets to the criteria... and later prepare them for the "search result" as FacetGroups
            // With the below only these values are in the result... no Red or RollsRoys
            Mediachase.Search.SimpleValue svWhite = new SimpleValue
            {
                value        = "white",
                key          = "white",
                locale       = "en",
                Descriptions = new Descriptions {
                    defaultLocale = "en"
                }
            };
            var descWhite = new Description
            {
                locale = "en",
                Value  = "White"
            };
            svWhite.Descriptions.Description = new[] { descWhite };

            // If added like this it ends up in "ActiveFields" of the criteria and the result is filtered
            //criteria.Add("color", svWhite);
            // ...also the facetGroups on the "result" are influenced

            Mediachase.Search.SimpleValue svBlue = new SimpleValue
            {
                value        = "blue",
                key          = "blue",
                locale       = "en",
                Descriptions = new Descriptions {
                    defaultLocale = "en"
                }
            };
            var descBlue = new Description
            {
                locale = "en",
                Value  = "Blue"
            };
            svBlue.Descriptions.Description = new[] { descBlue };
            //criteria.Add("color", svBlue);

            Mediachase.Search.SimpleValue svVolvo = new SimpleValue
            {
                value        = "volvo",
                key          = "volvo",
                locale       = "en",
                Descriptions = new Descriptions {
                    defaultLocale = "en"
                }
            };
            var descVolvo = new Description
            {
                locale = "en",
                Value  = "volvo"
            };
            svVolvo.Descriptions.Description = new[] { descVolvo };
            //criteria.Add("brand", svVolvo);

            Mediachase.Search.SimpleValue svSaab = new SimpleValue
            {
                value        = "saab",
                key          = "saab",
                locale       = "en",
                Descriptions = new Descriptions {
                    defaultLocale = "en"
                }
            };
            var descSaab = new Description
            {
                locale = "en",
                Value  = "saab"
            };
            svSaab.Descriptions.Description = new[] { descSaab };
            //criteria.Add("brand", svSaab);

            #region Debug

            // the above filters the result so only saab (the blue) is there
            // With the above only we see only the Blue shirt... is that a saab - yes
            // New: no xml --> gives one Active and an empty filter even searchFilter.Values.SimpleValue below is there
            // New: outcommenting the above line --> and add XML file ... no "Active Fileds"
            // Have the Filters added - but no actice fields
            // New: trying this... Brand gets "ActiveField" with volvo & saab.. but the result shows all brands
            // New: outcommenting the below line and adding above only one, the saab
            //criteria.Add("brand", new List<ISearchFilterValue> { svSaab, svVolvo });
            // ...get a FacetGroups "in there"... like with the XML-file ... a manual way to add...
            // ...stuff that is not in the XML-file, or skip the XML File
            // New: taking out the single saab filter added

            #endregion

            SearchFilter searchFilterColor = new SearchFilter
            {
                //field = BaseCatalogIndexBuilder.FieldConstants.Catalog, // Have a bunch
                field = "color",

                // mandatory
                Descriptions = new Descriptions
                {
                    // another way of getting the language
                    defaultLocale = _langResolver.Service.GetPreferredCulture().Name
                },

                Values = new SearchFilterValues(),
            };

            SearchFilter searchFilterBrand = new SearchFilter
            {
                field = "brand",

                Descriptions = new Descriptions
                {
                    defaultLocale = _langResolver.Service.GetPreferredCulture().Name
                },

                Values = new SearchFilterValues(),
            };

            var descriptionColor = new Description
            {
                locale = "en",
                Value  = "Color"
            };

            var descriptionBrand = new Description
            {
                locale = "en",
                Value  = "Brand"
            };


            searchFilterColor.Descriptions.Description = new[] { descriptionColor };
            searchFilterBrand.Descriptions.Description = new[] { descriptionBrand };

            searchFilterColor.Values.SimpleValue = new SimpleValue[] { svWhite, svBlue };
            searchFilterBrand.Values.SimpleValue = new SimpleValue[] { svVolvo, svSaab };

            // can do like the below or us the loop further down...
            // the "foreach (SearchFilter item in _NewSearchConfig.SearchFilters)"
            // use these in the second part of the demo... "without XML" ... saw that with XML-style
            criteria.Add(searchFilterColor);
            criteria.Add(searchFilterBrand);

            #region Debug

            // gets the "filters" without this below and the XML... further checks...
            // do we need this? ... seems not... or it doesn't work like this
            // New: Have XML and commenting out the below lines Looks the same as with it
            // New: second...outcommenting the criteria.Add(searchFilter);
            // the Facets prop is empty......without the XML
            // the below line seems not to work
            // New: adding these again together with the saab above active
            //... difference is the "VariationFilter"
            // We get the Facets on the criteria, but no facets in the "result" without the XML

            //criteria.Filters = searchFilter; // read-only

            // Without the XML...

            // boom... on a missing "key"... the description
            // when commenting out the criteria.Add() for the simple values...??
            // When adding more to the SearchFilter it works...
            // ... the Simple values are there in the only instance if the filter
            // commenting out and check with the XML
            // when using the XML the groups sit in FacetGroups
            // when using the above... no facet-groups added

            // The same facets added a second time, Filter number 2 and no facet-groups
            //SearchConfig sConf = new SearchConfig();

            #endregion Debug

            //*/
            #endregion SimpleValues

            // use the manager for search and for index management
            SearchManager manager = new SearchManager("ECApplication");

            #region Facets/Filters

            // Filters from the XML file, populates the FacetGroups on the Search result
            string _SearchConfigPath =
                @"C:\Episerver612\CommerceTraining\CommerceTraining\Configs\Mediachase.Search.Filters.config";

            TextReader    reader     = new StreamReader(_SearchConfigPath);
            XmlSerializer serializer = new XmlSerializer((typeof(SearchConfig)));
            _SearchConfig = (SearchConfig)serializer.Deserialize(reader);
            reader.Close();

            foreach (SearchFilter filter in _SearchConfig.SearchFilters)
            {
                // Step 1 - use the XML file
                //criteria.Add(filter);
            }

            // Manual...
            SearchConfig _NewSearchConfig = new SearchConfig
            {
                SearchFilters = new SearchFilter[] { searchFilterColor, searchFilterBrand }
            };

            // can do like this, but there is another way (a bit above)
            foreach (SearchFilter item in _NewSearchConfig.SearchFilters)
            {
                // Step 2 - skip the XML file
                //criteria.Add(item);
            }

            #endregion

            // Do search
            ISearchResults results = manager.Search(criteria);

            #region Debug


            // doens't work
            //FacetGroup facetGroup = new FacetGroup("Bogus", "Bummer");
            //results.FacetGroups = new[] { facetGroup };

            // ...different return types - same method
            //SearchFilterHelper.Current.SearchEntries()

            // out comment and do a new try
            //ISearchFacetGroup[] facets = results.FacetGroups;

            // NEW: adding these ... for the provider, last line doesn's assign
            //ISearchFacetGroup[] searchFacetGroup0 = new SearchFacetGroup() { };
            FacetGroup facetGroup0 = new FacetGroup("colorgroup", "dummy"); //{ "",""}; // FacetGroup("brand","volvo");
            Facet      f1          = new Facet(facetGroup0, svWhite.key, svWhite.value, 1);
            facetGroup0.Facets.Add(f1);
            //facets[1] = facetGroup0;
            ISearchFacetGroup[] searchFacetGroup = new FacetGroup[] { facetGroup0 };
            //searchFacetGroup.Facets.Add(f1);
            //results.FacetGroups = searchFacetGroup; // nothing happens here, facet-group still empty

            #endregion

            int[] ints = results.GetKeyFieldValues <int>();

            // The DTO-way
            CatalogEntryDto dto = _catalogSystem.GetCatalogEntriesDto(ints);

            // CMS style (better)... using ReferenceConverter and ContentLoader
            List <ContentReference> refs = new List <ContentReference>();
            ints.ToList().ForEach(i => refs.Add(_referenceConverter.GetContentLink(i, CatalogContentType.CatalogEntry, 0)));

            localContent = _contentLoader.GetItems(refs, new LoaderOptions()); //

            // ToDo: Facets
            List <string> facetList = new List <string>();

            int facetGroups = results.FacetGroups.Count();

            foreach (ISearchFacetGroup item in results.FacetGroups)
            {
                foreach (var item2 in item.Facets)
                {
                    facetList.Add(String.Format("{0} {1} ({2})", item.Name, item2.Name, item2.Count));
                }
            }

            var searchResultViewModel = new SearchResultViewModel
            {
                totalHits = new List <string> {
                    ""
                },                                   // change
                nodes      = localContent.OfType <FashionNode>(),
                products   = localContent.OfType <ShirtProduct>(),
                variants   = localContent.OfType <ShirtVariation>(),
                allContent = localContent,
                facets     = facetList
            };


            return(View(searchResultViewModel));
        }
Exemplo n.º 7
0
 /// <summary>
 /// Gets the catalog entries dto.
 /// </summary>
 /// <param name="catalogId">The catalog id.</param>
 /// <param name="parentNodeId">The parent node id.</param>
 /// <param name="responseGroup">The response group.</param>
 /// <returns></returns>
 public CatalogEntryDto GetCatalogEntriesDto(int catalogId, int parentNodeId, CatalogEntryResponseGroup responseGroup)
 {
     return(_Proxy.GetCatalogEntriesDto(catalogId, parentNodeId, responseGroup));
 }