The Pioneer Store also keeps track of and displays recent member searches. The word or words of each search are displayed as hyperlinks that bring the customer to the search results page, where a list of matching products and categories is displayed. For example, if the customer searched for a helmet and a water bottle, the list of hyperlinks would look like the screenshot below.
As in the case of recently viewed categories and products, we added a transient set property to the visitor’s profile: recentSearches
.
<item-descriptor name="user"> . . . <!-- This transient properties used to record recent user searches --> <property name="recentSearches" display-name="Recent user searches" data-type="set" component-data-type="String" /> . . .
This feature is supported by making modifications to the component /atg/commerce/catalog/CatalogSearch
. It is defined as an instance of atg.commerce.catalog.SearchFormHandler
; in the Pioneer Store, we extended this class with atg.projects.b2cstore.B2CSearchFormHandler
, which:
Adds a one-step search facility.
Generates a DMS message of type
atg.projects.b2cstore.search
whenever a search is performed, passing the search text as the body of the message.
One-step Search
The hyperlink brings the site visitor back to the Simple Search page (in the search subdirectory of the Pioneer Store site); clicking on this link also causes the search to be carried out. We did this by adding a property to the CatalogSearch
component: oneStepSearch
. The hyperlink sets this property to the recorded search string, and the search is carried out by the handleOneStepSearch()
handler prior to displaying the Simple Search page.
Send DMS Message to Scenario Server
In the Pioneer Store, the CatalogSearch
component, which performs all user searches, also sends the search string to the Scenario Server as a DMS message. Sending the message is delegated to a component that implements the atg.dms.patchbay.MessageSource
interface. The Pioneer StoreCatalogSearch
component uses the /atg/commerce/catalog/SearchEventSender
component to send its message. This component is identified by the SearchEventSender
property of the CatalogSearch
.
The SearchEventSender
component, an instance of atg.projects.b2cstore.SearchEventSender
, implements the MessageSource
methods, as well as the fireSearchEvent()
method, which issues a message to the Scenario Server.
public boolean fireSearchEvent(String searchString) { // Send message notifying that a search has been performed if (mStarted) { // if message source was successfully started try { SearchMessage search = new SearchMessage(); search.setSearchString(searchString); ObjectMessage msg = getMessageSourceContext().createObjectMessage(); msg.setObject(search); msg.setJMSType("atg.projects.b2cstore.search"); getMessageSourceContext().sendMessage(msg); } catch (JMSException jmse) { System.out.println("Error sending message recording search: " + jmse); } } return true; }
Tying all this together involves configuring the Patch Bay to deliver a message from the SearchEventSender
to the Scenario Server. A message type must be defined, SearchEventSender
identified as a message source for this kind of message, and the Scenario Server identified as a message sink. For more information on the Patch Bay, refer to the chapter on the Dynamo Message System in the ATG Programming Guide. Here is an overview of the Patch Bay configuration file provided by the Pioneer Store:
<ATG9dir>/atg/dynamo/messaging/dynamoMessagingSystem.xml
<dynamo-message-system> <patchbay> <message-source> <nucleus-name> /atg/commerce/catalog/SearchEventSender </nucleus-name> <output-port> <port-name> DEFAULT </port-name> <output-destination> <provider-name> local </provider-name> <destination-name> localdms:/local/DPSTopic/CatalogSearchEvents </destination-name> <destination-type> Topic </destination-type> </output-destination> </output-port> </message-source> <message-sink> <nucleus-name> /atg/scenario/ScenarioManager </nucleus-name> <input-port> <port-name> IndividualEvents </port-name> <input-destination> <provider-name> local </provider-name> <destination-name> localdms:/local/DPSTopic/CatalogSearchEvents </destination-name> <destination-type> Topic </destination-type> </input-destination> </input-port> </message-sink> </patchbay> <!-- local JMS definitions --> <local-jms> <jndi-prefix>/local</jndi-prefix> <topic-name>/DPSTopic/CatalogSearchEvents</topic-name> </local-jms> <!-- message registry definitions --> <message-registry> <message-family> <message-family-name> atg </message-family-name> <message-type> <jms-type> atg.projects.b2cstore.search </jms-type> <message-class> atg.projects.b2cstore.SearchMessage </message-class> <message-context> request </message-context> <display-name> Searches the catalog </display-name> <description> Generated when user searches a catalog </description> </message-type> </message-family> </message-registry> </dynamo-message-system>