Displaying Search History in XSLT on your Google Mini or Google Search Appliance
March 23rd, 2010
The Steps To Implement Search History On A Google Search Appliance or Google Mini
A few weeks ago there was a thread on the Google Groups regarding how to display search history on a Google Search Appliance query results page. Our approach typically at MC+A is to utilize the xslt as much as possible as it provides less complicated infrastructure. Because of this, we tend to utilize JQuery to provide some dynamics features to the interface. In this case, it’s search history. This article assumes you have some idea about jQuery, specifically the Ready function.
Step 1 – Create A DIV
Create a HTML DIV in your results page that you would like the history to be displayed. For example:
<div id=”recentHistory”>No Recent Searches</div>
Note the id that you use for later in this process. You can also place text with the div that will be displayed until the jQuery finishes loading.
Step 2 – Add A Function Call to jQuery.Ready
$(document).ready(function(){
setHistory(); //Function to set the Div
});
Step 3 – Add the Function Call
The following function relies on 5 other functions:
- GetCookieVal – Get’s the Cookie Value
- GetCookie – Get’s a raw Cookie
- DeleteCookie – Delet’e’s a Cookie
- SetCookie – Set’s a Cookie
- GetParameter – Get’s a Query String Value
function setHistory(){
var gsaCollection = getParameter(window.top.location.search.substring(1), "site");
var gsaClient = getParameter(window.top.location.search.substring(1), "client");
var gsaStylesheet = getParameter(window.top.location.search.substring(1), "proxystylesheet");
//var gsaAccess =getParameter(window.top.location.search.substring(1),"a");
var recentHistory = "<ul>";
var historyTemp = GetCookie("searchhistory");
var history;
if (historyTemp == null) {
var q = getParameter(window.top.location.search.substring(1), "q")
if ((q == null) || (q == "")) {
//no history
recentHistory = recentHistory + "<li>None</li>";
}
else {
recentHistory = recentHistory + "<li><a href=\"search?site=" + gsaCollection + "&client=" +
gsaClient +
"&proxystylesheet=" +
gsaStylesheet +
"&access=a" +
"&q=" +
q +
"&output=xml_no_dtd" +
"\" > " +
q +
"</a></li>";
SetCookie("searchhistory", q, expiry);
}
}
else {
historyString = new String(historyTemp);
history = historyString.split("|");
var newHistory = new Array(5);
var newHistoryString = "";
newHistory[0] = getParameter(window.top.location.search.substring(1), "q");
newHistoryString = newHistory[0];
recentHistory = recentHistory + "<li><a href=\"search?site=" + gsaCollection + "&client=" +
gsaClient +
"&proxystylesheet=" +
gsaStylesheet +
"&access=a" +
"&output=xml_no_dtd" +
"&q=" +
newHistory[0] +
"\" > " +
newHistory[0].replace(‘+’, ‘ ‘) +
"</a></li>";
for (var i = 0; i < history.length & i < 4; i++) {
newHistory[i + 1] = history[i];
newHistoryString = newHistoryString + "|" + history[i];
recentHistory = recentHistory + "<li><a href=\"search?site=" + gsaCollection + "&client=" +
gsaClient +
"&proxystylesheet=" +
gsaStylesheet +
"&access=a" +
"&output=xml_no_dtd" +
"&q=" +
history[i] +
"\" > " +
history[i].replace(‘+’, ‘ ‘) +
"</a></li>";
}
SetCookie("searchhistory", newHistoryString, expiry);
}
recentHistory = recentHistory + "</ul>";
document.getElementById("recentSearches").innerHTML = recentHistory;
}
I am planning on cleaning up the function and posting it here it its entirety in the next couple of days.;
Reply with a comment to nudge me along if I forget.



