Drop Shadow

Customized Search Results

The easiest way to set up a search for your portion of the USD web site is the “indexing your site” option. All it requires is that you make an HTML form. However, if you need more control over the format of the search results, you can use PHP to insert search results into your pages.

The basic search

The easiest way to create a search is to:

  1. include the searches PHP plug-in
  2. create a new search for your site
  3. tell the new search to display everything needed for a search

For example, these three lines will create a search of the web coding section of the web site:

<? include_once('/web/includes/searches.phpi'); $search = new search('/webdev/coding/'); $search->Page(); ?>

The first line includes the plug-in, the second line creates a search restricted to /webdev/coding/ and the third line displays the form, as well as any search results if the form has been submitted.

It will be best to put the first two lines at the very top of your web page:

<? include_once('/web/includes/searches.phpi'); $search = new search('/webdev/coding/'); ?>

Put the other line where you want the form and search to show up:

<? $search->Page(); ?>

If you want some special text in front of the form, place that text in quotes in $search->Page():

$search->Page('Search the USD Web Coding site:');

Style sheet

You have full control over the appearance of the search results using style sheets. We have a pre-defined search style sheet at “/css/google.css”. You can use this style sheet by adding the following HTML to the HEAD section of your web page:

<link rel="stylesheet" href="/css/google.css" type="text/css" media="all" />

You can, of course, replace our search style sheet with your own, or use our search style sheet and override some elements in your own sheet.

Sample Search

<? include_once('/web/includes/searches.phpi'); $search = new search('/webdev/coding/'); $search->Page(); ?>

Show omitted results

By default, Google will not display search results that it thinks are too similar to search results it has already shown; it tries to show the most relevant, and then provides a link to show the omitted results. If you want to display the omitted results by default, add this line of PHP before you display the form and results:


Breaking it up

You might wish to create your own form, or to place some extra text between the form and the results.

$search->Form()Display a simple search form.
$search->Results()Display results if there are any.
$search->Logo()Display the search page’s logo.

Style classes

Several classes are used in the search page. You can customize them in your own style sheet.

div.searchSurrounds the output of $search->Page().
img.searchlogoThe logo of the search engine we’re using.
p.pretextThe text passed to $search->Page().
form.searchThe search form.
input.termsThe search term input field.
input.submitThe search submit button.
div.searchresultsSurrounds the search results.
div.titlebarSurrounds the summary of the search results.
div.gresultsSurrounds the general results.
div.resultitemSurrounds each result.
div.resulttitleSurrounds each result’s title.
span.mimetypeSurrounds each result’s mimetype.
span.lSurrounds each result’s title text.
div.snippetSurrounds each result’s sample text.
div.infoSurrounds each result’s page information.
span.res_urlSurrounds each result’s URL.
span.res_sizeSurrounds each result’s file size.
span.res_dateSurrounds each result’s modification date.
div.subitemSurrounds any related items.
div.morelinksSurrounds the link to more related items.
div.nSurrounds the number links to more pages of results.

Special characters in the search results

Because the search results contain many special characters, your page’s character set must be UTF-8. The customized search include tries to do this automatically, but it can only do it automatically if you create the search as the very first thing on your web page. This means putting the first two lines—the “include_once” and the “$search = new search()” lines—at the very top of your page.

If you don’t put the include where it can automatically set the character set, you’ll need to change the content-type yourself by adding this HTML to the HEAD section of your web page:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />