Page tree
Skip to end of metadata
Go to start of metadata

If you need to add a search box that searches only a portion of the website, e.g. /bucs then this is how to do it.

How to set one up

In the example below, the scope parameter restricts the search. The others (collection and profile) are required for the search to work at all. The input box must be named "query".

<form action="" method="get" id="keywordsearch">
    <input type="text" class="findPeopleInputBox" maxlength="255" size="14" name="query" tabindex="1" id="gsinput1" onfocus="if (this.value == 'keyword search') {this.value=''}" value="keyword search"> 
    <input type="image" name="submit" id="gsgo" value="btnG" src="" alt="search"> 
    <input type="hidden" name="collection" value="website">
    <input type="hidden" name="profile" value="_default">
    <input type="hidden" name="scope" value="learningandteaching/rdu/courses/pgskills/modules/">

The classes and IDs on the example form, input box and button are purely for styling and not required. There is an example of this on in the right hand column.

The scope filters by performing a sub-string match to the document's URL. This can produce strange results if scope is not as specific as the example above. If we have this:

   <input type="hidden" name="scope" value="/study/">

It will match:

To eliminate polis (and other erroneous results) we need to use something like:

  <input type="hidden" name="scope" value="">

Note that changing this variable does change the text on the search results page (see below).

The template output

Example search result:

In this section of the simple.ftl template we check if the scope parameter was passed and we tell the user that their search is restricted. This is the only difference to a normal output.

<@s.IfDefCGI name="scope">
<p id="fb-scope">
    in <span><@s.Truncate length=80>${question.inputParameterMap["scope"]!?html}</@s.Truncate></span>
    - Search all of
    <a href="?query=<@s.URLEncode><@s.QueryClean></@s.QueryClean></@s.URLEncode>&amp;collection=${question.inputParameterMap["collection"]!?url}&amp;profile=${question.inputParameterMap["profile"]!?url}"></a>.