I am trying to integrate a site search feature into a clie开发者_如何学运维nt'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:
- The search form posts back to the site
- The POST page uses an API to get the result back from Google
- 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!
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.
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.
精彩评论