Adding Google Search Appliance Suggest Search To Your Existing Page

July 28th, 2009

“Suggest” is a new beta feature on the Google Search Appliance 6.0.  Out of the box, it is designed to work with the default style sheet.  However, many of our clients have chosen to use a scripted page (asp/aspx/php/jsp).  In order to get this functionality working, additional coding is required.  This article describes wiring up the search box via a proxy and asp.

The Service

There is a new service located at /suggest.  When you type the queries are sent to it.  The response comes back as a simple JSON package.  It is not encoded in JSONP so if you develop a separate page and want to use it, you’re faced with  a cross site scripting issue.

The Solution

  1. Copy suggest_js.js to the site which you want to utilize the service.
  2. Create a proxy in your server (code below)
  3. suggest_js.js is obfuscated.  But you just need to replace “/suggest” with the location of your new service (has to be at the same domain
  4. Add the .ac-renderer, .ac-row, .ac-highlighted and .ac-active styles to your page
  5. reference the new suggest_js.js file is reference in your html
  6. call the function sgst(‘q’);
  7. Start typing!

Proxy Example:

dim srcFile
srcFile = "http://gsa.mcplusa.com/suggest?"
srcFile = srcFile & "token=" & Request("token") & "&max_matches=10"</div>
'Get the JSON
Response.Buffer = True
Dim objXMLHTTP, xml

'Create an xmlhttp object
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", srcFile, False
xml.Send

Response.Write xml.responseText
set xml= Nothing

The New Suggested Search running off the appliance.

Update!

Mahesh T published a java servlet here.

3 Responses to “Adding Google Search Appliance Suggest Search To Your Existing Page”

  1. Gords Says:

    Does this still work for the latest GSA version (6.8)? Also, how do I create the Proxy?

  2. @michaelcizmar Says:

    In principle yes, however Google has updated the JavaScript and the stylesheets. For one, the code is not obfuscated any longer (nor does the css reference corp.google.com :) ).

    There is more information here: http://code.google.com/apis/searchappliance/docum…

    But you still need to get the request from the browser to the GSA some how. You can also create a proxy with an apache configuration or some simple code in C#. java, php, etc. Good luck!

  3. Michael Says:

    Yes and no. The suggest service has been redesigned (it no longer references css/images in corp.google.com :) ) You can get the updated scripts from the gsa directly.