Create a Search Function
Current version: 8.2
Enable free text searches on a Sitecore Commerce 8.2 powered by Commerce Server and Commerce Server 11.4 website.
Complete the following prerequisites:
At your visual studio solution setup
-
Use
SearchHelpers.GetFacetFieldsForItem
to retrieve facets for this page. -
Use
SearchHelpers.GetSortFieldsForItem
to get any specific sort fields that are expected to be used on this page. -
Use
SearchHelpers.GetFacetFieldsForItem
to retrieve facets for this page. -
Create an instance of the
CommerceSearchOptions
class. UseSearchNavigation.GetCatalogItem
to actually search for the term, you need to pass it a search term and an instance of the options class.RequestResponseshellvar searchManager = CommerceTypeLoader.CreateInstance<ICommerceSearchManager>(); var requiredFacets = searchManager.GetFacetFieldsForItem(this.Item); var sortFields = searchManager.GetSortFieldsForItem(this.Item); var searchKeyword = "boots"; var catalogName = "Adventure Works Catalog"; var currentPageNumber = 0; var productSearchOptions = new CommerceSearchOptions(Constants.Settings.DefaultItemsPerPage, currentPageNumber); var searchResponse = SearchNavigation.SearchCatalogItemsByKeyword(searchKeyword, catalogName, searchOptions); if (searchResponse != null) { var foundItems = searchResponse.ResponseItems; var totalProductCount = searchResponse.TotalItemCount; var totalPageCount = searchResponse.TotalPageCount; var facets = searchResponse.Facets; }