Google Hacks Free Open Book

Google Hacks

Previous Section Next Section

Hack 10 Hacking Google Search Forms

figs/beginner.giffigs/hack10.gif

Build 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 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 two ways: via hidden variables or by adding more input to your form.

10.1 Hidden Variables

As 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.

While it's perfectly legal HTML to put your hidden variables anywhere between the opening and closing <form> tags, it's rather tidy and useful to keep them all together after all the visible form fields.

File type

As the name suggests, file type specifies filtering your results by a particular file type (e.g., Word DOC, Adobe PDF, PowerPoint PPT, plain text TXT). Add a PowerPoint file type filter, for example, to your search form like so:

<input type="hidden" name="as_filetype" value="PPT">
Site search

Narrows your search to specific sites. While a suffix like .com will work just fine, something more fine-grained like the example.com domain is probably better suited:

<input type="hidden" name="as_sitesearch" value="example.com">
Date searching

Narrows your search to pages indexed within the stated number of months. Acceptable values are between 1 and 12. Restricting our results to items indexed only within the last seven months is just a matter of adding:

<input type="hidden" name="as_qdr" value="m7">
Number of results

Specifies the number of results you'd like appearing on each page, specified as a value of num between 1 and 100; the following asks for 50 per page:

<input type="hidden" name="num" value="50">

What would you use this for? If you're regularly looking for an easy way to create a search engine that finds certain file types in a certain place, this works really well. If this is a one-time search, you can always just hack the results URL [Hack #9], tacking the variables and their associated values on to the URL of the results page.

10.2 Mixing Hidden File Types: An Example

The 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.

Even though you're creating a handy search form this way, you're still resting on the assumption that Google's indexed most or all of the site you're searching. Until you know otherwise, assume that any search results Google gives you are incomplete.

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.

10.3 Creating Your Own Google Form

Some 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>
<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">
</form>
<!-- Custom Google Search Form-->

FaganFinder (http://www.faganfinder.com/engines/google.shtml) is a wonderful example of a thoroughly customized form.

    Previous Section Next Section


         Main Menu
    Main Page
    Table of content
    Copyright
    Dedication
    Credits
    Foreword
    Preface
    Chapter 1. Searching Google
    1.1 Hacks #1-28
    1.2 What Google Isn't
    1.3 What Google Is
    1.4 Google Basics
    1.5 The Special Syntaxes
    1.6 Advanced Search
    Hack 1 Setting Preferences
    Hack 2 Language Tools
    Hack 3 Anatomy of a Search Result
    Hack 4 Specialized Vocabularies: Slang and Terminology
    Hack 5 Getting Around the 10 Word Limit
    Hack 6 Word Order Matters
    Hack 7 Repetition Matters
    Hack 8 Mixing Syntaxes
    Hack 9 Hacking Google URLs
    Hack 10 Hacking Google Search Forms
    Hack 11 Date-Range Searching
    Hack 12 Understanding and Using Julian Dates
    Hack 13 Using Full-Word Wildcards
    Hack 14 inurl: Versus site:
    Hack 15 Checking Spelling
    Hack 16 Consulting the Dictionary
    Hack 17 Consulting the Phonebook
    Hack 18 Tracking Stocks
    Hack 19 Google Interface for Translators
    Hack 20 Searching Article Archives
    Hack 21 Finding Directories of Information
    Hack 22 Finding Technical Definitions
    Hack 23 Finding Weblog Commentary
    Hack 24 The Google Toolbar
    Hack 25 The Mozilla Google Toolbar
    Hack 26 The Quick Search Toolbar
    Hack 27 GAPIS
    Hack 28 Googling with Bookmarklets
    Chapter 2. Google Special Services and Collections
    Chapter 3. Third-Party Google Services
    Chapter 4. Non-API Google Applications
    Chapter 5. Introducing the Google Web API
    Chapter 6. Google Web API Applications
    Chapter 7. Google Pranks and Games
    Chapter 8. The Webmaster Side of Google
    Colophon
    Index


    More Books
    PHP Hacks
    Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
    The Koran (Holy Qur'an)
    Macromedia Flash 8 Bible
    Search Engine Optimization for Dummies
    YouTube Traffic
    PHP 5 for Dummies
    Harry Potter and The Chamber of Secrets
    Harry Potter and the Sorcerer's Stone
    The Pilgrim's Progress
    Wireless Hacks
    Flash Hacks. 100 Industrial-Strength Tips & Tools
    PayPal Hacks. 100 Industrial-Strength Tips and Tools
    Amazon Hacks
    Pdf Hacks
    The Da Vinci Code
    Google Hacks
    The Holy Bible
    Windows XP For Dummies
    Harry Potter and the Half-Blood Prince
    Seo Book
    Upgrading and Repairing Networks
    Macromedia Dreamweaver 8 UNLEASHED
    Windows XP Annoyances
    Windows XP Hacks
    Microsoft Windows XP Power Toolkit
    Teach Yourself MS Office In 24Hours
    iPod & iTunes Missing Manual
    PC Hacks 100 Industrial-Strength Tips and Tools
    PC Overclocking, Optimization, and Tuning - 2th Edition
    PC Hardware In A Nutshell 3rd Edition
    PC Hardware in a Nutshell, 2nd Edition
    Upgrading and Repairing PCs
    Google for Dummies
    MySQL Cookbook
    Teach Yourself Macromedia Flash 8 In 24 Hours
    PHP CookBook
    Sams Teach Yourself JavaScript in 24 Hours
    PHP5 Manual
    Free Games Paper Airplanes
    500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele