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:
- include the searches PHP plug-in
- create a new search for your site
- 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(); ?>
What would you like to find on our site?
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:
$search->showOmitted();
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.search | Surrounds the output of $search->Page(). |
|---|---|
| img.searchlogo | The logo of the search engine we’re using. |
| p.pretext | The text passed to $search->Page(). |
| form.search | The search form. |
| input.terms | The search term input field. |
| input.submit | The search submit button. |
| div.searchresults | Surrounds the search results. |
| div.titlebar | Surrounds the summary of the search results. |
| div.gresults | Surrounds the general results. |
| div.resultitem | Surrounds each result. |
| div.resulttitle | Surrounds each result’s title. |
| span.mimetype | Surrounds each result’s mimetype. |
| span.l | Surrounds each result’s title text. |
| div.snippet | Surrounds each result’s sample text. |
| div.info | Surrounds each result’s page information. |
| span.res_url | Surrounds each result’s URL. |
| span.res_size | Surrounds each result’s file size. |
| span.res_date | Surrounds each result’s modification date. |
| div.subitem | Surrounds any related items. |
| div.morelinks | Surrounds the link to more related items. |
| div.n | Surrounds 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 linesthe “include_once” and the “$search = new search()” linesat 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" />
