Code to Perform a Free-Text Search of a Catalog
The following code example shows a wrapper function that performs a free text search. It uses typical values for return properties and sorting properties, and simplifies performing a free text search by building the parameters for a call to the CatalogManager.FreeTextSearch method.
The constants used to build the values of the sPropertiesToReturn
and sPropertiesToSortOn
variables will need to be defined according to your catalog schema.
' Function: rsFreeTextSearch
'
' Description:
' Performs a Free-Text Search using typical values.
' Returns the results as a recordset.
' iRecordCount gets set to the number of records retrieved.
'
' Parameters:
' sPhrase - the freetext string to find
' iStartingRecord - return results starting from this record#
' iRecordsToRetrieve - return max. this many records
' iRecordCount - return the actually retrieved number
' of records in this parameter
'
' Returns:
' Recordset with search results
' -----------------------------------------------------------------------
Function rsFreeTextSearch(ByVal sPhrase, _
ByVal iStartingRecord, _
ByVal iRecordsToRetrieve, _
ByRef iRecordCount)
' Declare variables:
Dim sPropertiesToReturn
Dim sPropertiesToSortOn
Dim rsResult
Dim iClassType
Dim sCatalogsToSearch
' Build the parameter strings to select
' properties to return and to control sorting:
' "name" and "description" are required product
' properties and cannot have null values.
sPropertiesToReturn = PRODUCT_NAME_PROPERTY_NAME & "," & _
PRODUCT_DESCRIPTION_PROPERTY_NAME & "," & _
CATALOG_NAME_PROPERTY_NAME & "," & _
CATEGORY_NAME_PROPERTY_NAME & "," & _
CATALOG_PRODUCTID_PROPERTY_NAME & "," & _
CATALOG_VARIANTID_PROPERTY_NAME & "," & _
DEFINITION_TYPE_PROPERTY_NAME
' "name" is a required product property and cannot have a null value.
sPropertiesToSortOn = CATEGORY_NAME_PROPERTY_NAME & "," & _
PRODUCT_NAME_PROPERTY_NAME
' Determine what catalogs to search.
' This example assumes that you will always search two catalogs:
' CatalogA and CatalogB. You could get this parameter by having
' the user select which catalogs to search, or from a function
' that selected catalogs based on a user profile.
sCatalogsToSearch = "CatalogA, CatalogB"
' Determine the type of data wanted. This example will return
' categories, products, and product families.
iClassType = cscProductFamilyForVariantsClass Or _
cscProductClass Or _
cscCategoryClass
' Call the FreeTextSearch method and return the recordset.
Set rsFreeTextSearch = _
MSCSCatalogManager.FreeTextSearch( _
sPhrase, _
sCatalogsToSearch, _
iClassType, _
sPropertiesToReturn, _
sPropertiesToSortOn, _
True, _
iStartingRecord, _
iRecordsToRetrieve, _
iRecordCount _
)
End Function