August 07, 2008
Custom Search with Yahoo BOSS and PHP
by Marco Vitanza

BOSS (Build your Own Search Service) is Yahoo's new open search platform. Using the BOSS API, developers have access to Yahoo's entire search index to create custom searches, mashups, and more. Read more about it here.

A practical (and simple) use for BOSS is to build a custom search page so that users can search your website. I wrote a simple search page to do this using PHP with the CURL extension.

Let's take a look at the steps needed to execute a simple site search with BOSS and PHP:

  1. Get a query from a user (web form).
  2. Build the BOSS query URL with your Yahoo AppID and other parameters.
  3. Submit the query to BOSS (using a CURL GET request)
  4. Receive the XML (or JSON) data from BOSS.
  5. Parse the XML and display the results.

Try out the search here.

View the code here (formatted).

Download the code here (text).

UPDATED: Added support for multiple result pages.

”
Comment by Flame on September 01, 2008 at 07:40am
That's nice a simple, thanks a lot for the code.
”
Comment by Sudhanshu on November 11, 2008 at 11:50am
Pretty cool. Terrific job
”
Comment by Robert on January 20, 2009 at 10:29am
Hi, Do you by chance also have a code example for image and or news search? I also have a PHP script available, but also only for regular search: http://www.subscribetomyblog.com/spotlight/yahoo-boss-php-code-examples-are-hard-to-come-by
”
Comment by Robert on January 20, 2009 at 10:46am
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?
”
Comment by desbest on January 31, 2009 at 12:59am
I prefer BOSS's JSON and XML output format than that Google Web Search API coz they got rid of the xml output feature. I know JQuery, xml, and php, but I've never worked with xml before. Thanks to you I can use BOSS so easily and have something to learn xml from. Thanks alot. You're awesome!
”
Comment by Nick on February 19, 2009 at 09:27am
Thank you very much for the code. I am no XML or PHP expert and i'm trying to get your example work so I can adapt it for a sirte of mine. I have got my own app code but whatever I search for I get 0 results. I want this to be an external search - would I remove '&site=' from the query ?
”
Comment by dawilster on June 26, 2009 at 09:20am
I dont no if your've realised but your script is unable to process & symbols, every time i retrieve a url with a symbol such as the "&" symbol the url becomes distorted, ive been looking through the code countless time and cant seem to find a solution would you mind helping me out. thanks a lot
”
Comment by Anonymous on August 24, 2009 at 04:06pm
When I search I get no results?
”
Comment by Tun on October 22, 2009 at 03:34am
thanks alot
”
Comment by Renesa on November 18, 2009 at 07:59pm
When I search I also dont get any result why is that? please reply ASAP. What I have to do to see the results?
”
Comment by Rish on September 26, 2010 at 03:36am
Doesn't seem to be working!
”
Comment by Mike on February 10, 2011 at 09:12am
Excellent script - just what I was after. Gives me a really professional-looking search program to use on my websites. Rish - I found it works if you call the php file "custom_search.php". Just make sure you put your own API code into the php file and also list your own website in the file (without the http://www. part). Cheers Mike
”
Comment by Mike on March 26, 2011 at 02:59pm
Thanks, great script.
”
Comment by Abhiram on May 22, 2012 at 07:58am
Can you give an updated script for Boss V2, the current script does not seem to work with the new version. Thanks in advance !!!
”
Comment by jasmin on July 25, 2012 at 07:25am
is it necessary to pay to the yahoo boss for running this example?
”
Comment by jasmin on July 25, 2012 at 07:30am
in your 'Try out the search' nothing will be searched when I typed yahoo or ipad.Can you explain.
”
Comment by Cayle on October 17, 2012 at 01:38pm
If you want to get read, this is how you shuold write.

Post Comment

Name:
Comment:  
Security Code: Verification Code Five Digits