Share via


Performing category searches in the catalog system

          Just as you can perform freetext and/or property searches on one or more catalogs in the catalog system you can also perform freetext and/or property searches on a single category in a catalog. When you do a category search the search criteria is applied to the descendants of the category.A category search can be non-recursive in which case only the immediate descendants (child categories and products) of the category will be searched or recursive in which case all the descendants of the category will be searched. When you do a category search you should specify the category name for the CatalogSearch.CategoryName property and CatalogSearch.CatalogNames property should contain the name of the catalog containing the category. By default, a category search is non-recursive and you can perform a recursive search by setting the CatalogSearch.Recursive property to true.

          The following sample code recursively searches the  “Autobiographies“ category in the “Books” catalog containing the word “leader“ and having a price less than 40:

           CatalogContext catalogContext = CommerceContext.Current.CatalogSystem;
           CatalogSearchOptions catalogSearchOptions = new CatalogSearchOptions();
            catalogSearchOptions.ClassTypes = CatalogClassTypes.ProductClass;
            catalogSearchOptions.PropertiesToReturn = "[ProductId],[Name],[Description]";
            catalogSearchOptions.SortProperty = "Name";
            catalogSearchOptions.SetPaging(1, 20);
           CatalogSearch catalogSearch = new CatalogSearch(catalogContext);
            catalogSearch.SearchOptions = catalogSearchOptions;
            catalogSearch.Language = "en-US";
            catalogSearch.CatalogNames = "Books";
            catalogSearch.CategoryName = "Autobiographies";
            catalogSearch.Recursive = true;
            catalogSearch.FreeTextSearchPhrase = "leader";
            catalogSearch.SqlWhereClause = "[cy_list_price] < 40";
            int totalRecords = 0;
            DataSet catalogSearchResults = catalogSearch.Search(out totalRecords);

Comments

  • Anonymous
    May 21, 2006
    One of my posts (Catalog classtypes and search functionality in the catalog system) described the search...