Tutorial: Create a Yahoo BOSS powered Site Search Engine

Written by Amit Agarwal on Aug 21, 2010

yahoo-boss While it is extremely easy to implement Google Custom Search in your site, the Google service is kind of limited in the sense that you little control over the search results that display on your site. You can neither reorder search results nor can you include additional information in the search pages.

Enter Yahoo BOSS, a service overcomes most limitations of Google Custom Search. It lets you display search results in the format you like, or add image thumbnails to your results page (similar to Cuil) or you can even hide certain web pages from appearing in search results.

If you like to experiment with Yahoo! Boss for your own site search, here’s a quick tutorial to help you get started. Just apply for an AppID and then replace the appropriate values in the following PHP file.

<font color="#008000">// Get the Yahoo BOSS AppID from https://developer.yahoo.com/wsregapp/</font> 
define ('APP_ID', 'YOUR_APPID_HERE');

<font color="#008000">// Restrict site search to your own domain - replace labnol.org</font>
$query = $_GET ['q'] . '+site:labnol.org';

<font color="#008000">// Get search results from Yahoo BOSS as an XML*</font> 
$API = 'http://boss.yahooapis.com/ysearch/web/v1/';
$request = $API . $query .'?format=xml&amp;appid='. APP_ID; 

$ch = curl_init($request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HEADER, 0);
$xml = simplexml_load_string (curl_e xec($ch)); 

<font color="#008000">// Display search results - Title, Date and URL.</font> 
foreach ($xml-&gt;resultset_web-&gt;result as $result) {
 print '&lt;a href=&quot;'.$result-&gt;clickurl.'&quot;&gt;'.$result-&gt;title.'&lt;/a&gt;&lt;br /&gt;'; 

*You can directly use file_get_contents() instead of the cURL library but some web hosts (like Dreamhost) do not allow fopen on external files.

Tweak Your Search Results

These results (like Gmail, Google Chrome, India) are presented in a plain vanilla interface but you could easily wrap them in a WordPress plug-in that displays addition information next to search results like associated thumbnail images, tags, number of comments, etc. To see all this in action, check out the gmail search on TechCrunch.

Ads in Yahoo! Boss

Yahoo! has promised that they’ll brings ads to Yahoo! Boss so you will be able to monetize site search in the same manner as AdSense for Search. It may however be limited to US residents only since you require a valid SSN to gain entry into the Yahoo Ad Network.

Update: Make sure that you use the ClickURL value for the HREF value in your search results and not the direct URL as this is a requirement according to their BOSS API terms of use.

Subscribe to our Email Newsletter