CU Home
Columbia University Information Technology
Add a Search Box

Web Design > Google Search > Add a Search Box

Add a Search Box to Your Site

Contents:

Create a Basic Search Box

You can add a basic search box to your web site to help visitors find content.

  1. Insert the following HTML into your web page where you want the search box to appear:

    <form method="get" action="http://search.columbia.edu/search">
    <input type="text" name="q" alt="Search" value="" maxlength="256" size="32" />
    <input type="submit" name="btnG" value="Search" />
    <input type="hidden" name="site" value="Columbia" />
    <input type="hidden" name="client" value="columbia" />
    <input type="hidden" name="proxystylesheet" value="columbia" />
    <input type="hidden" name="output" value="xml_no_dtd" />
    <input type="hidden" name="filter" value="0" />
    </form>
  2. Customize the following required parameters:
    • name="q" size="32"
      Sets the width (in number of characters) of the search box. You can change the size to suit your site's layout, but don't change the maxlength value.

    • name="btnG" value="Search"
      The text that appears on the search button, e.g.: value="Search Departmental Site"
    • name="client" value="columbia"
      name="proxystylesheet" value="columbia"
      name="site" value="Columbia"

      The client parameter specifies the Google frontend your search will use. The proxystylesheet parameter specifies the XSLT stylesheet. You will probably not change these unless you have a custom frontend built for your site.

      Note: In most cases, the client value should be identical to the proxystylesheet value. The only time you would want different values for the two parameters is when you want to retain the frontend's KeyMatch, Synonyms, Filters, and Remove URL settings, but change to a different output format.
      The site parameter specifies the Google collection. The default value="Columbia" searches the entire Columbia Google collection. To search a different collection, change the value to the name of the collection you want to use.
      e.g.: value="CUIT"


Here is an working example of a basic search of the main Columbia site, using the above code:




Restrict Your Search by Site: Single Site

If you want to restrict your search feature to a specific directory (and its subdirectories), include the following two lines in your form:

<input type="hidden" name="as_dt" value="i"/>
<input type="hidden" name="as_sitesearch" value="<yoururl>"/>
If you don't include these lines, the search feature on your site will search the entire Columbia collection.
  • name="as_dt" value="i"
    This setting determines whether your search should include or exclude the directory specified in "as_sitesearch". Values can be:

    • "i" (include only results in the web directory specified by as_sitesearch)
    • "e" (exclude all results in the web directory specified by as_sitesearch)
  • name="as_sitesearch" value="<yoururl>"
    Pages in the specified directory will be included in or excluded from your search (according to the value of "as_dt").
    e.g.: name="as_sitesearch" value="www.columbia.edu/cu/biology"

    • You must specify the complete canonical name of the host server followed by the path of the directory.
      e.g.: www.columbia.edu/services not www/services

    • If you include a slash ("/") character is at the end of the web directory path, then only files within that directory will be searched and files in sub-directories will not be considered. e.g.:
      • www.columbia.edu/services to include sub-directories
      • www.columbia.edu/services/ to exclude sub-directories
    • as_sitesearch allows allows you to specify one directory (and all its sub-directories) as the domain to be searched—you cannot specify multiple disparate directories using this option.


Here is an working example of a search restricted to a single site, in this case the Biology Department:



Restrict Your Search by Site: Specifying Multiple Sites

If you want to restrict your search feature to a more than one specific directory (and its subdirectories), include the following in your form instead of the parameters as_dt and as_sitesearch:

<input type="hidden" name="as_oq" value="<firsturl secondurl>"/>
  • name="as_oq" value="<firsturl secondurl>"
    This parameter adds one or more search terms (or URLs), combined with boolean OR. e.g. as_oq="http://www.worldleaders.columbia.edu http://www.sipa.columbia.edu"/


Here is an working example of a search of multiple sites, in this case SIPA and the World Leaders Forum:



Restrict Your Search by Searcher-Selected Sub-Area

Use the following code to include a drop-down list of different areas of your site from which people can choose.

<form method="get" action="http://search.columbia.edu/search">
<input type="text" name="q" alt="Search" value="" maxlength="256" size="32"/>
<input type="submit" name="btnG" value="Search" />
<input type="hidden" name="site" value="Columbia"/>
<input type="hidden" name="client"value="columbia" />
<input type="hidden" name="proxystylesheet" value="columbia" />
<input type="hidden" name="output" value="xml_no_dtd"/>
<input type="hidden" name="filter" value="0"/>
<input type="hidden" name="as_dt" value="i"/>

<br />Select an area to search:
<select name="as_sitesearch">
<option value="url1">Section Name 1
<option value="url2">Section Name 2
</select>
</form>

For each URL/Name pair, enter a complete URL to limit the search and a label to describe it, e.g.

<option value="http://www.law.columbia.edu/faculty">Faculty Directory
  • You must specify the complete canonical name of the host server followed by the path of the directory.
    e.g.: www.columbia.edu/services not www/services

  • If you include a slash ("/") character is at the end of the web directory path, then only files within that directory will be searched and files in sub-directories will not be considered. e.g.:
    • www.columbia.edu/services to include sub-directories
    • www.columbia.edu/services/ to exclude sub-directories

You can include as many options in the drop-down menu as you want, although the sample only shows two.

Tip: You will probably want to include an option to search your entire site. Place it first in the list, and it will appear as the default selection:

<option value="http://www.law.columbia.edu">Entire Law School
<option value="http://www.law.columbia.edu/faculty">Law School Faculty


Here is an working example of a search with a drop-down menu of options:

Search the Law School

Select an area to search: