How do I limit the searchTermHistory cookie size?

Technote (troubleshooting)


Problem(Abstract)

There are no pre-set limits on the size of the searchTermHistory cookie, so it can grow indefinitely.

Symptom

The searchTermHistory cookie on shopper browsers may grow very large in size.


Resolving the problem

1. Open the Stores.war/<store>/javascript/Widgets/Search.js file for edit.

2. Create a new config variable:

if(typeof(SearchJS) == "undefined" || SearchJS == null || !SearchJS){

SearchJS = {
...
TOTAL_HISTORY_TO_RETAIN : 5,
...

3. Update the cookie matching logic:

...
var historyList = "";
var searchHistorySection = document.getElementById("autoSuggestHistory");
searchHistorySection.innerHTML = "";
var historyArray = new Array();
this.historyIndex = listCount;

var searchHistoryCookie = getCookie("searchTermHistory");
if(typeof(searchHistoryCookie) != 'undefined') {
var termsArray = searchHistoryCookie.split("|");
var count = 0;
for(var i = 0; i < termsArray.length; i++) {
var theTerm = termsArray[i];
var theLowerTerm = theTerm.toLowerCase();
if(theLowerTerm.match("^"+searchTermLower) == searchTermLower) {
historyList = historyList + "<li id='suggestionItem_" + listCount + "' role='listitem' tabindex='-1'><a href='#' onmouseout='this.className=\"\"' onmouseover='SearchJS.enableAutoSelect(" + listCount + ");' onclick='SearchJS.selectAutoSuggest(this.title); return false;' title=\"" + theTerm + "\" id='autoSelectOption_" + listCount+ "'><strong>" + searchTerm + "</strong>" + theTerm.substring(searchTerm.length, theTerm.length) + "</a></li>";
historyArray.push(theLowerTerm);
count++;
listCount++;
if(count >= this.TOTAL_HISTORY) {
break;
}
}
}
}


if(historyList != "") {
...

4. Update the cookie update function:

/**
* Updates the searchTermHistory cookie value...
*/
updateSearchTermHistoryCookie:function(updatedSearchTerm){
if(updatedSearchTerm.length > 0) {
var cookieKey = "searchTermHistory";
var cookieValue = updatedSearchTerm;
var searchTermHistoryCookie = getCookie(cookieKey);
if(typeof(searchTermHistoryCookie) != 'undefined') {
var cookieArray = dojo.cookie(cookieKey).split("|");
var limit = Math.min(this.TOTAL_HISTORY_TO_RETAIN - 1, cookieArray.length);
for(var i = 0; i < limit; i++) {
if(cookieArray[i] == updatedSearchTerm) {
// existing search term in history
return;
}
cookieValue = cookieValue + "|" + cookieArray[i];
}
}
dojo.cookie(cookieKey, cookieValue, {path:'/'});
}
},

updateSearchTermHistoryCookieAndRedirect:function(updatedSearchTerm, redirectURL){
this.updateSearchTermHistoryCookie(updatedSearchTerm);
document.location.href = redirectURL;
},

isValidNumber:function(n) {
return !isNaN(parseFloat(n)) && isFinite(n) && n >= 0;
},

/**
* Validation method for advanced search form
*/

Rate this page:

(0 users)Average rating

Add comments

Document information


More support for:

WebSphere Commerce Enterprise
Catalog

Software version:

7.0

Operating system(s):

AIX, IBM i, Linux, Solaris, Windows

Reference #:

1635228

Modified date:

2013-05-21

Translate my page

Machine Translation

Content navigation