Sign in

E-mail *, (xx@domain.com)
Password *

Register | Forgot password

Recent blogs

Using Google Custom Search on your site

September 17, 2008

GX WebManager comes with a very well equipped search engine based on Apache Lucene. But suppose you don’t have the time or resources to setup and tune a search engine and just want a plain out the box popular search engine?  Google Custom Search might be a nice alternative for you. Occasionally we get this question from our customers and I will show you that implementing this is really easy and straightforward.

Create a custom search engine

Creating the search engine

To create a Google Custom Search Engine  - or CSE as I will call it from now on – go to

http://www.google.com/coop/cse/

 You need a Google or Gmail account to create a CSE.
  • Click on the button ‘Create a Custom Search Engine’.
  • By entering basic information such as name, description, language and site details you can setup your search engine. As an example I created a custom search engine for GX Developerweb. I selected ‘Only sites I select’ and entered only one URL: http://www.gxdeveloperweb.com 
Entering the details
  • You  can choose the standard edition with banners (Google’s got to earn some money too) or if you have a small budget ($100/year) or are lucky to be a non-profit institution or government agency you can choose the business edition.
  • You can test the fresh CSE in step 2
  • Go to ‘My search engines’  (URL: http://www.google.com/coop/manage/cse/) and click on the ‘control panel’ link
  • Click on the ‘code’ link.
  • Change the ‘hosting options’ setting to ‘Host results on your website’ and choose the iframe option.
  • From the code in the ‘Search box code’ field, copy the value of the hidden field ‘cx’. This should be a code like ‘014765577166074708146:t_bphqhesla
  • Create a presentation WCB with one JSPf file with the following code:
<%@ page language="java" session="false" buffer="none" %>
<%@ taglib uri="http://www.gx.nl/taglib/wm" prefix="wm"%>
<form action="${presentationcontext.page.link.url}" id="cse-search-box">
  <div>
    <input type="hidden" name="cx" value="014765577166074708146:t_bphqhesla" />
    <input type="hidden" name="cof" value="FORID:11" />
    <input type="hidden" name="ie" value="UTF-8" />
    <input type="text" name="q" size="31" />
    <input type="submit" name="sa" value="Search" />
  </div>
</form>
<script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en"></script>
<div style="overflow: auto">
	<div id="cse-search-results"></div>
	<script type="text/javascript">
	  var googleSearchIframeName = "cse-search-results";
	  var googleSearchFormName = "cse-search-box";
	  var googleSearchFrameWidth = 450;
	  var googleSearchDomain = "www.google.com";
	  var googleSearchPath = "/cse";
	</script>
	<script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>
</div>

The only thing that has to be changed in this JSPf is the CX value in the same hidden form field. Replace it by the value you copied from Google. Create an XML descriptor file for the JSPf and give it the same scope as the GX WebManager Search Element

<presentation>
  <name>GXlabs Google Custom Search element</name>
  <display-name>GXlabs Google Custom Search element</display-name>
  <scope>SearchElement</scope>
</presentation>
The final result

Additional steps

From here on its time to play around with your CSE and JSPs. Some ideas:

  • You can set the background colors and presentation in Google, add additional banners (AdWords), or set up a business edition. Just check all the tabs in the CSE generator
  • You can upgrade to a business account to get rid of the banners legally. This will also allow you to retrieve the search results in raw XML format. That enables a much nicer integration than an iframe. For example you could display the search results by using AJAX calls or integrate search results with the WebManager presentation layer. 
  • Combine the Google CSE  with the GX WebManager search engine. This gives visitors the choice between various search engines. A real life example is the Google CSE implementation at HetNet:

    http://www.hetnet.nl This is a combination between web search handled by Google and local site search handled by the GX WebManager search engine.

  • This simple presentation WCB could be replace by a special Google Custom Element WCB where you can enter the CX id manually and add more customization parameters.

You can dump your creations in the comments!

About the Author

Return to all blogs


Martin van Mierloo is Product Manager and has many years of experience with GX WebManager. Martin writes about the GX WebManager roadmap, new product features and WCMS related topics..
Read all Martins blog entries

Other blog entries:

December 24, 2008
The year has almost ended...
October 22, 2008
New certification process
October 17, 2008
Search quest [3/3] - improvements
October 17, 2008
New in 9.6: Import/export
July 16, 2008
New in WebManager 9.5 part 2: Personalization API
July 10, 2008
New in WebManager 9.5 part 1: Content API additions
June 27, 2008
Ease of implementation
June 18, 2008
Content Management and Sustainability
May 28, 2008
Search quest [2/3] - Relevance
March 13, 2008
Search quest [1/3]


Share:

del.icio.us
digg
Technorati
Slashdot
Reddit
YahooMyWeb
NewsVine
ekudos
© 2008 GX creative online development B.V.

Disclaimer

This website (GXdeveloperweb.com) may discuss or contain opinions, (sample) coding, software or other information that does not include GX official interfaces, instructions or guidelines and therefore is not supported by GX. Changes made based on this information are not supported.  GX will not be held liable for any damages caused by using or misusing the information, software, instructions, code or methods suggested on this website, and anyone using these methods does so at his/her own risk. GX offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this website, including any liability resulting from incompatibility between the content of this website and the materials and services offered by GX. By using this website you will not hold, or seek to hold, GX responsible or liable with respect to the content of this website.