views:

393

answers:

2

I am trying to integrate a site search feature into a client's site. I've created an test search engine with Google Custom Search, but I can't sort out how to make it work with the following criteria:

  1. The search form posts back to the site
  2. The POST page uses an API to get the result back from Google
  3. I display the results within my site

Am I misunderstanding how Google Custom Search works? Is there a simple tutorial somewhere that fits my criteria?

Thanks!

+1  A: 

Google Custom Search Business Edition specifically has the API to return XML results, with which you can do what you please. Business Edition is not free.

Here is the XML results documentation.

From PHP, you can use cURL to pass your POSTed search query on to Google CSE as a GET request, and then do whatever you want with the XML server side or client side.

Dolph
I suspected that the API was a Business Edition feature, but I couldn't find it explicitly stated. I'm going to try the cURL method, and see what I get back.
Sonny
+1  A: 

Check out http://www.google.com/cse/docs/resultsxml.html

But basically yeah: have a page on your site that when it gets a post/get variable it makes an http request to Google containing (at least) your search term and your api key, it then receives a load of XML in return which it then formats and returns on the page.

It's pretty straightforward. I've not implemented it in PHP, which judging by your tag is the lanaguage you're looking to do it in, but something like http://www.seopher.com/articles/google_custom_search_tutorial_using_xml_and_php_ should put you on the right track.

Apemantus