Building a (re)search interface for Yahoo, Bing and Google with YQL
If you do a lot of research using web searches can be frustrating. Different search engines have different results, you need to open things in tabs and in general it can be pretty time consuming to find what you need.
To make this a bit easier I thought it’d be cool to have an interface that searches Yahoo, Google and Bing at the same time and thus I built GooHooBi:
As explained in the screen cast the thing under the hood of GooHooBi is YQL. Instead of fussing about with all the different search APIs all I did was to play with the YQL console and put together the following YQL statement:
select * from query.multi where queries='
select Title,Description,Url,DisplayUrl
from microsoft.bing.web(20) where query="cat";
select title,clickurl,abstract,dispurl
from search.web(20) where query="cat";
select titleNoFormatting,url,content,visibleUrl
from google.search(20) where q="cat"
'
The query.multi table in YQL allows you to list a few queries which will be executed one after the other on the YQL server. The queries themselves I put together by using the different tables in the console and only selecting what I really need from each of them.
You can try this query in the YQL console and you can see the JSON output.
The rest is pretty easy. Cut this up into a parameterized string and do a cURL call:
$query = filter_input(INPUT_GET, 'search', FILTER_SANITIZE_SPECIAL_CHARS);
$queries[] = 'select Title,Description,Url,DisplayUrl '.
'from microsoft.bing.web(20) where query="'.$query.'"';
$queries[] = 'select title,clickurl,abstract,dispurl '.
'from search.web(20) where query = "'.$query.'"';
$queries[] = 'select titleNoFormatting,url,content,visibleUrl '.
'from google.search(20) where q="'.$query.'"';
$url = "select * from query.multi where queries='".join($queries,';')."'";
$api = 'http://query.yahooapis.com/v1/public/yql?q='.
urlencode($url).'&format=json&env=store'.
'%3A%2F%2Fdatatables.org%2Falltableswithkeys&diagnostics=false';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$data = json_decode($output);
Then loop over the results and assemble the HTML output.
You can check the source code of GooHooBi.
- The HTML/JavaScript version JS source JS live.
- The PHP version PHP source PHP live
- The PHP “API” API source API live
In addition to this, here’s a half hour live coding screencast how to build something similar:
Building a search mashup with YQL using Google, Yahoo and Bing – live :) from Christian Heilmann on Vimeo.
The source of the code built in this screencast is also on GitHub.
Tags: api, demo, Google, live, mashup, microsoft, yahoo, yql


December 9th, 2009 at 6:14 pm
Interesting article from codepo8 on using YQL to query google,bing and yahoo at once as a research tool: [link to post] #yql
– Posted using Chat Catcher
December 9th, 2009 at 6:15 pm
Reading: Building a (re)search interface for Yahoo, Bing and Google with YQL - [link to post]
– Posted using Chat Catcher
December 9th, 2009 at 6:35 pm
That is impressive, what all you can do with one query! In the past for doing the same thing I was using the SOAP from Google, Serialized PHP format from Yahoo and RSS from MSN in other words nightmare.
I was convinced that YQL is just for the Yahoo products obviously I was wrong. After Google killed my small search engine based on their old SOAP system I was in search of alternative apis so few days ago I was trying Yahoo BOSS and I must say I’m very happy with the results. Pure and clear naming logic and no limits for number of queries.
About YQL i was curious if can handle broken XML and what is the problem with feedburner?
@ToAllSearchEngines: Can you guys make one universal api standard for all search engines?
Christian thank you for your tutorial and code!
December 9th, 2009 at 10:23 pm
RT @frederikvig: Reading: Building a (re)search interface for Yahoo, Bing and Google with YQL - [link to post]
– Posted using Chat Catcher
December 10th, 2009 at 10:55 am
I like the research mode :) I played with Google Ajax Search API a few years back and made something like that but with only google’s results: http://peekstr.com
December 10th, 2009 at 6:38 pm
Easily searching Yahoo, Bing and Google with YQL (via @fedecarg, @freekrai) [link to post] #yql
– Posted using Chat Catcher
December 10th, 2009 at 9:38 pm
Building a search interface for Yahoo, Bing and Google with YQL [link to post] (@codepo8) #api #yql
– Posted using Chat Catcher
December 11th, 2009 at 1:01 pm
Thanks for this Christian. I’m finding it so useful I’ve added to my FF search bar, and added it to Mycroft – http://mycroft.mozdev.org/search-engines.html?name=GooHooBi
December 16th, 2009 at 10:39 pm
AWESOME!! this brings the idea of website which allows u todo web research. lil extra features e.g one click to save a link on evernote. :P
December 25th, 2009 at 3:36 pm
Usefull article for me, for my engineer work. best regards
January 24th, 2010 at 8:05 pm
Thanks Dan Champion for link to GooHooBi – FF – mycroft