Integrating Google Search API to AC Gold

From AbleCommerce Wiki
Jump to: navigation, search

Google WebSearch service provides a powerful way to display search results for the customers to their own web sites. It also provides complete control over customizing search results. It is very easy to integrate Google Custom Search API in Ablecommerce. This article will discuss the integration of Google Custom Search API in ablecommerce.

First of all, we need to define a Custom Search Engine using google control panel. Here is the step by step procedure to do this:

To create a custom search engine:

  • Sign into Control Panel [1] using your Google Account (create new account if you don't already have one).
  • In the Sites to search section, add the pages you want to include in your search engine. You can include any sites you want, not just the sites you own. You can include whole site URLs or individual pages URLs. You can also use URL patterns.
  • The name of your search engine will be automatically generated based on the URLs you select. You can change this name at any time.
  • Select the language of your search engine. This defines the language of the buttons and other design elements of your search engine, but doesn't affect the actual search results.
  • Click Create.

Now the basic search engine setup is completed and ready to use. There are three required parameters that must be sent in search request, these parameters are:

1. client

The client parameter must be set to google-csbe

2. output

The output parameter specifies the format of the returned XML results; results can be returned with (xml) or without (xml_no_dtd) a reference to Google's DTD. We recommend setting this value to xml_no_dtd. Note: If you do not specify this parameter, then results will be returned in HTML instead of XML.

3. cx

The cx parameter which represents the unique ID of the CSE. This cx value can be obtained from Details section from search engine setup control panel.

For more details and adding other advanced optional parameters, visit API reference guide here [2]

Google Search Engine API Integration sample Code

You can download the sample code.

Place the downloaded code files to your website root directory. All you need now is to only replace the cx parameter value to your website's cx from google custom search engine setup page. Now access the GoogleSearch.aspx in browser and try searching some keywords, it should return the results as expected. You can customize your store header to use this new google search page.

IMPORTANT: Google offers this free custom search engine (Custom Search Engine aka CSE) but it includes Google ads at the top of the search results. They also offer a paid plan (Google Site Search), which starts at $100 for 20K searches/year (50 queries per day).