< Day Day Up > |
Hack 18. Hack Your Own Google Search FormBuild your own personal, task-specific Google search form. If you want to do a simple search with Google, you don't need anything but the standard Simple Search form (the Google home page). But if you want to craft specific Google searches that you'll be using on a regular basis or providing for others, you can simply put together your own personalized search form. Start with your garden-variety Google search form; something like this will do nicely: <!-- Search Google --> <form method="get" action="http://www.google.com/search"> <input type="text" name="q" size=31 maxlength=255 value=""> <input type="submit" name="sa" value="Search Google"> </form> <!-- Search Google --> This is a very simple search form. It takes your query and sends it directly to Google, adding nothing to it. But you can embed some variables to alter your search as needed. You can do this in two ways: via hidden variables or by adding more input to your form. 1.30.1. Hidden VariablesAs long as you know how to identify a search option in Google, you can add it to your search form via a hidden variable. The fact that it's hidden just means that form users will not be able to alter it. They won't even be able to see it unless they take a look at the source code. Let's take a look at a few examples.
1.30.2. Mixing Hidden File Types: An ExampleThe site tompeters.com (http://www.tompeters.com) contains several PowerPoint (.ppt) files. If you want to find just the PowerPoint files on their site, you'd have to figure out how their site search engine works or pester them into adding a file type search option. But you can put together your own search form that finds PowerPoint presentations on the tompeters.com site.
Your form looks something like: <!-- Search Google for tompeters.com PowerPoints --> <form method="get" action="http://www.google.com/search"> <input type="text" name="q" size=31 maxlength=255 value=""> <input type="submit" name="sa" value="Search Google"> <input type="hidden" name="as_filetype" value="ppt"> <input type="hidden" name="as_sitesearch" value="tompeters.com"> <input type="hidden" name="num" value="100"> </form> <!-- Search Google for tompeters.com PowerPoints --> Using hidden variables is handy when you want to search for one particular thing all the time. But if you want to be flexible in what you're searching for, creating an alternate form is the way to go. 1.30.3. Creating Your Own Google FormSome variables best stay hidden; however, for other options, you can let your form users be much more flexible. Let's go back to the previous example. You want to let your users search for PowerPoint files, but you also want them to be able to search for Excel files and Microsoft Word files. In addition, you want them to be able to search tompeters.com, the State of California, or the Library of Congress. There are obviously various ways to do this user-interface-wise; this example uses a couple of simple pull-down menus: <!-- Custom Google Search Form--> <form method="get" action="http://www.google.com/search"> <input type="text" name="q" size=31 maxlength=255 value=""> <br /> Search for file type: <select name="as_filetype"> <option value="ppt">PowerPoint</option> <option value="xls">Excel</option> <option value="doc">Word</option> </select> <br /> Search site: <select name="as_sitesearch"> <option value="tompeters.com">TomPeters.com</option> <option value="state.ca.us">State of California</option> <option value="loc.gov">The Library of Congress</option> </select> <input type="hidden" name="num" value="100"> <input type="submit" value="Search Google"> </form> <!-- Custom Google Search Form--> FaganFinder (http://www.faganfinder.com/engines/google.shtml) is a wonderful example of a thoroughly customized form. |
< Day Day Up > |