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.

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: , , , , , , ,

11 Responses to “Building a (re)search interface for Yahoo, Bing and Google with YQL”

  1. freekrai (Roger Stringer) Says:






    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

  2. frederikvig (Frederik Vig) Says:






    Reading: Building a (re)search interface for Yahoo, Bing and Google with YQL - [link to post]

    Posted using Chat Catcher

  3. Vladimir Carrer Says:

    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!

  4. jamesgaisford (James Gaisford) Says:






    RT @frederikvig: Reading: Building a (re)search interface for Yahoo, Bing and Google with YQL - [link to post]

    Posted using Chat Catcher

  5. Predrag Stojadinovic Says:

    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

  6. AdrianSchneider (Adrian Schneider) Says:






    Easily searching Yahoo, Bing and Google with YQL (via @fedecarg, @freekrai) [link to post] #yql

    Posted using Chat Catcher

  7. fedecarg (Federico Cargnelutti) Says:






    Building a search interface for Yahoo, Bing and Google with YQL [link to post] (@codepo8) #api #yql

    Posted using Chat Catcher

  8. Dan Champion Says:

    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

  9. Markandey Singh Says:

    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

  10. kredyt Says:

    Usefull article for me, for my engineer work. best regards

  11. hilding Says:

    Thanks Dan Champion for link to GooHooBi – FF – mycroft

Wait till I come! is the blog of Christian Heilmann , a developer evangelist living and working in London, England. Download vcard.

Feed me, Seymour: Entries (RSS) and Comments (RSS).