Creating a Custom Search Engine (CSE) / Create a Search Box for Your Department

Method A:  To create a search that will display the results on the same page, use a Custom Search Engine (CSE).

There are many options for a CSE. These instructions will get you started with a basic CSE.

  1. Login to http://www.google.com/cse/ with a gmail account
  2. Click on "Add" at the top right corner.
  3. Fill out the form
    1. Enter a search engine name.
    2. In the "What to search?" section, select "Search specific sites or pages" and enter a site URL to search. Click "Add".
  4. Click on the "Create" button.
  5. On the "Your new search engine has been created" page, copy the code and paste the code into your page.

To customize the look of your search form on your page:

  1. Go the "Look and feel" section of your Search Engine.
  2. Click on "All Look and Feel settings"
  3. Select your desired layout.
  4. Click on the "Get Code" button.
  5. In the popup, click in the grey text box. The code will now be highlighted.
  6. Copy the code.
  7. Paste the code into your page.

Method B:  To create a search that will display the results on a new page with the UH template, use Google's University Search.

Google has updated their CSE code. Please see https://developers.google.com/custom-search/docs/element for more information.

If you'd like to include a search box that will only search within your department's pages, you might try including the form below. It uses Google's search engine, but limits the results to only matches within your department's directory or site. If you set this up and get no results, please contact us.

Copy the below text to your page and replace "its" in the placeholder and hq input tag to the directory you want to search.

<?php
session_start();
$q = '';
if (isset($_SESSION['q'])) {
        $q = $_SESSION['q'];
        unset($_SESSION['q']);
}


$hq = '';
if (isset($_SESSION['hq'])) {
        $hq = $_SESSION['hq'];
        unset($_SESSION['hq']);
}

if (isset($_REQUEST['q'])) {
        $_SESSION['q'] = $_REQUEST['q'];
        $_SESSION['hq'] = $_REQUEST['hq'];
        header('Location: ?q=' . $_REQUEST['q'] . '%20' . $_REQUEST['hq']);
        exit;
} // END check if q parameter passed
// IMPORTANT: all of the above code must be before anything else. 
// Template or page content goes below
?>
<form action="">
            <input name="q" type="text" size="40" value="<?php echo $q; ?>" placeholder="Search /its" />
            <input name="hq" type="hidden" value="inurl:its" />
            <input type="submit" name="sa" value="Search" />

</form>
<script>
        (function() {
                var cx = '008945998903415758105:4nrwh9-26ni';
                var gcse = document.createElement('script');
                gcse.type = 'text/javascript';
                gcse.async = true;
                gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
                var s = document.getElementsByTagName('script')[0];
                s.parentNode.insertBefore(gcse, s);
        })();
</script>
<gcse:searchresults-only></gcse:searchresults-only> 

 


 

Please rate the quality of this answer: Poor Fair Okay Good Excellent
Not the answer you were looking for? Try different keyword combinations and if you still can’t find your answer, please contact us.
Article ID: 711
Created: Wed, 14 Feb 2007 8:50am
Modified: Mon, 26 Feb 2024 10:58am