Partager via


CatalogSearch Class

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

Used to search catalogs. Use this class to perform searches against product, variant, and category data in one or more catalogs.

Namespace:  Microsoft.CommerceServer.Catalog
Assembly:  Microsoft.CommerceServer.Catalog (in Microsoft.CommerceServer.Catalog.dll)

Syntax

'Declaration
Public NotInheritable Class CatalogSearch _
    Inherits CatalogObjectBase
'Usage
Dim instance As CatalogSearch
public sealed class CatalogSearch : CatalogObjectBase
public ref class CatalogSearch sealed : public CatalogObjectBase
public final class CatalogSearch extends CatalogObjectBase

Remarks

You can use the CatalogSearch class to perform a variety of searches on catalogs, including:

  • Search all the catalogs in the catalog system specifying a property search and/or freetextsearch.

  • Search a single catalog in the catalog system specifying a property search and/or freetextsearch.

  • Search a category in a catalog in the catalog system specifying a property search and/or freetextsearch. When doing a category search you should specify only one catalogname.

  • Recursively search a category in a catalog in the catalog system specifying a property search and/or freetextsearch.

You can also use CatalogSearch to perform property, free text, or both property and free text searches. The CatalogSearchOptions class allows you to specify the properties to return in the CatalogItemsDataSet, the properties to sort the results by and the class types in the returned results. You can even page the search results by specifying starting record and the number of records. For multilingual sites, you can specify the language in which to perform the search and in which to return the content.

The maximum number of results returned by a Catalog Search is limited by the MaxSearchResults value in the catalog webservice web.config.

Examples

// Search a catalog
// name="catalogName"
internal CatalogItemsDataSet SearchCatalog(string catalogName)
{
  CatalogSearchOptions searchOptions = new CatalogSearchOptions();
  searchOptions.PropertiesToReturn = "CategoryName, DefinitionName, i_classtype, ProductId, VariantId, DisplayName";
  searchOptions.SetPaging(1, 20);
  searchOptions.SortProperty = "CategoryName";
  CatalogSearch catalogSearch = this.catalogContext.GetCatalogSearch();
  catalogSearch.CatalogNames = catalogName;// This is a comma separated list of catalogs to search eg "Catalog1,catalog2"
  catalogSearch.SqlWhereClause = "cy_list_price<10";// Return all items with price less than 10
  catalogSearch.UseAdvancedFreeTextSearch = true;// 
  catalogSearch.AdvancedFreeTextSearchPhrase = "\"sql books\""; // Returns all rows which contain the phrase "sql books"
  /*
   *  Inventory Integration: Set the inventory options here
    catalogSearch.InventoryOptions = new InventoryOptions();
    catalogSearch.InventoryOptions.FilterOutOfStockSkus = true; // Do not return products which are out of stock
   */
  /* To restrict searches to  a single category
    catalogSearch.CategoryName = "categoryname";
    catalogSearch.Recursive = true;
   */
  int totalRecords = 0;
  CatalogItemsDataSet catalogItems = catalogSearch.Search(out totalRecords);
  Console.WriteLine(totalRecords);
  foreach (CatalogItemsDataSet.CatalogItem catalogItem in catalogItems.CatalogItems)
  {
    Console.WriteLine(catalogItem.CategoryName);
    Console.WriteLine(catalogItem.DisplayName);
  }
  return catalogItems;
} 

Inheritance Hierarchy

System..::.Object
  Microsoft.CommerceServer.Catalog..::.CatalogObjectBase
    Microsoft.CommerceServer.Catalog..::.CatalogSearch

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

CatalogSearch Members

Microsoft.CommerceServer.Catalog Namespace