Google Custom Search API are wonderful tools to create some awesome search engine like tools. Also if you want to add a search option to your website and customize the look and feel of your search results, Google Custom Search API serve best to you.
I have created a Real Time Search engine (I call it real time as it search as you type). I am really impressed by the speed/response of Google Search API.
I will show the code for one of the search api that I implemented in demo page. Let us see how to implement Web Search API.
In order to use Google Search API, you have to first generate a Key for you. Go to following page and signup your self for the Key.
Sign up for Google API Key
Step 2: Add HTML Container for Web Search
We will create a textbox and a button that will take input for search. And a DIV that will be populated by results:
When user will write a query and push Search button, a request will be made to Google Search using Custom Search API and the results are fetched. These results are then copied into the DIV.
The code in plain english is:
1. Create an object to connect Google Web search using class
2. Set a callback function that will get call once the results for the search are fetched.
3. Call the
execute() method with search query as argument.
4. In callback function, iterate through the results and copy it to container DIV.