How to build search into your site with JQuery and Yahoo!

Bookmark and Share

Yahoo have a hard time fighting off the image of being bridesmaid to Google’s bride. However, they have a decided knack for turning out really cool developer toys! For example, check out the Yahoo User Interface library, Yahoo Pipes, or their latest baby, Yahoo BOSS.

Short for ‘Build your Own Search Service’, Yahoo have pretty much opened up their entire search service via an API. With an unrestricted number of queries, and complete control over presentation of results, you can really go to town with this one!

Getting started is easy; simply get yourself an API key here. Go on, I’ll wait.

With that done, anyone with basic knowledge of PHP and JQuery can easily build a search application!

Check out my demonstration here.

There are two pages involved in this demonstration. The first page displays the form, and contains the necessary JQuery code to fire off an AJAX request to the second page. The second page takes the posted value, fires off a request to the API, and returns the result.

Without further ado, here’s the JQuery:

    $(document).ready(function(){
      $('#results').hide();

      $('#search').click(function(){
        $('#results').hide();
        searchterm = $('#searchterm').val();
        $.post('getresult.php', {query: searchterm}, function(data){
          $('#results').html(data).show('slow');
        });
      })
    })

Nothing too horrendous here; hide the results division, grab the term to be searched for, fire off an AJAX request, and put the returned data in the results div. Show it slloooooowly. :)

The code in ‘getresult.php’ isn’t much more complex; you can see it here.

That’s all there is to it! (At least for this very basic example.)

Once again, you can see a demonstration here.

I’m sure there must be loads of ideas for mashups out there; let’s hear some of your thoughts!

Tags: , , ,

This entry was posted on Thursday, July 31st, 2008 at 9:06 pm and is filed under AJAX, PHP, jquery, web development. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

 

12 Responses to “How to build search into your site with JQuery and Yahoo!”

  1. “The Complete Guide” for jQuery Developer- Reblog « Dynamic Disruption Says:

    [...] How to build search into your site with JQuery and Yahoo!Build your site search with jQuery and Yahoo. [...]

  2. mattNo Gravatar Says:

    What, no YUI? :)

  3. graham muddNo Gravatar Says:

    Graham here from the BOSS team at Yahoo! Thanks for the props! If you build a mashup with BOSS, let us know about it. We’re always looking for innovative apps to show off. Send me an email (gmudd at yahoo-inc.com) or tag on delicious with “bossmashup.” Thanks!

    Graham

  4. TylerNo Gravatar Says:

    This is a very nice looking project. Nice work

  5. RyanNo Gravatar Says:

    Nice use of JQuery and AJAX.

    I should have thought of it! Nice work John.

  6. kellyNo Gravatar Says:

    I love yahoo pipes. When I create squidoo lenses, I can create a custom feed to put in the RSS module. Good stuff. Question is, will yahoo ever compete head on with Google? Hard to say :)

  7. SJL Web DesignNo Gravatar Says:

    You have to love some of the development tools Yahoo have been creating recently, this is no exception. Excellent use of jquery, AJAX and php.

  8. ChrisNo Gravatar Says:

    Wow, BOSS looks really good, maybe its the Facebook Connect for search and we will see some cool apps in the next time :)

  9. RobertNo Gravatar Says:

    Hi I also have a search engine based on Yahoo Boss. You can download the PHP script from my blog if you want.: http://www.subscribetomyblog.com/spotlight/yahoo-boss-php-code-examples-are-hard-to-come-by. Do you by the way have a PHP script for image search with Yahoo Boss?

  10. Creare DesignNo Gravatar Says:

    Boss is looking really good! Excellent Jquery, looks smooth.

  11. Landlords SteveNo Gravatar Says:

    I love the jquery and boss owns!

  12. MattrixNo Gravatar Says:

    This looks great, and almost exactly what I’m looking for, but is it possible to make it so it only searches your site and not the whole net? If so, how?