Recipe search engines are all then rage these days, with a new example cropping up every week. This in-depth tutorial will show you how to make your own and provides working code for you to download.
We’ll be using Yahoo’s BOSS to do the hard work for us, so the first thing you need to do is sign up for a Yahoo account, if you don’t have one already.
Yahoo BOSS is a great service that allows you to use their search engine and brand the results however you like. It is completely free for most uses, with fees only applying if you use it more than 10,000 times per day.
Get A Yahoo BOSS Application ID
This is pretty straightforward. Fill in the form here and make a note of the long, hexadecimal App ID that gets spat out afterwards. Here is an example of how to fill out the form:
We’ll be using BOSS to provide search results across a range of recipe sites, so we don’t need to do anything difficult (like creating a data service). It’s just like entering a site: operator into the normal Yahoo search.
I’ve chosen these sites to search, but you can easily modify the script to supply your own choices:
Build A Search Front-End
Next, we need a web front-end to accept user input and call the BOSS service and then display the results. There’s some ready made PHP code for you to download here which we’ll go through to get a thorough understanding of just what is going on.
The code performs the following actions:
- Display a header and search form
- Check if the form has been filled and submitted, if it has:
- Send the query to our BOSS service
- Parse the reply from BOSS
- If there were some search results
- Display the search results
- Else
- Print “No results found”
- That’s it!
Note: I’m going to assume that the reader is familiar with basic HTML and PHP code. If you’re new to this sort of stuff, there are some great tutorials here and here.
The results are output pretty much unstyled so you should put your HTML skills to work on prettifying the presentation.
So, on to the code...
Display A Header & Search Form
The header will extract and sanitise any input variables, then output a HTML header.
Note: You need to replace YOUR_APP_ID with the Yahoo BOSS application ID you got at the beginning of this tutorial.
The search form is quite straight forward, see this tutorial on HTML forms if you’re unsure of what is going on here.
Was The Form Filled Previously?
We just need to check for the presence of the search terms:
Send The Query To BOSS
It is a simple HTTP GET so PHP’s file_get_contents() will work (unless your host has disabled it, in which case read this for a work around).
The script builds a URL using our application ID, list of sites to search and the query string. This URL returns the results in JSON, which is easy to parse into a PHP structure.
Did We Get Some Results?
Error checking is important - we don’t want to confuse users if there was a problem - so we’ll check the output carefully. We must also check whether any results were found.
Loop Through The Results And Display Them
This is pretty easy but I’ve not styled the output in any way. There are CSS classes in the output though, so you could just add your own external stylesheet to the header.
Try It Out And Download The Script
You can see my script in action here and the source is available for download here.
When you try it, you’ll see that it is very rough but it should provide a reasonable foundation for you to build something upon. Here are some suggestions for improvement:
- Style everything - add a CSS stylesheet and make the output pretty
- Add some analytics - find out what your users are searching for
- Show recent searches - if you want to dive into the code, you could show the last ten searches by recording them in a database
- Display some adverts - make a bit of cash
- Add an OpenSearch plug-in - maybe even break out the AJAX and provide search suggestions
I hope you find this useful, both as inspiration for building a recipe search and an introduction to the power of Yahoo BOSS. If you have any questions or suggestions then please leave a comment and don’t forget to subscribe to the feed for more articles like this.
Creative Commons licensed picture by silver marquis.




web-development
del.icio.us
Furl
Google Bookmarks
reddit
Simpy
Sphinn
StumbleUpon
Yahoo MyWeb
Post On Fire
Google Buzz



Very intresting.