Exercise 5: Customize search

Customize the advanced search form, and make it the default

Introduction:

The default XTF search form is a simple keyword form, but an advanced form is also available, allowing the user to search for specific terms in specific fields. This form can be customized to suit your collection and application, and can also be set as the default.

Three files interact to produce the search forms. These files are located within the %XTF_HOME%\style\crossQuery directory:

resultFormatter/default/searchForms.xsl
resultFormatter/default/resultFormatter.xsl
resultFormatter/common/resultFormatterCommon.xsl

This exercise demonstrates how these files work together and how to customize them.

Demonstration:

Steps:

  1. Using your XML editor, open:

    %XTF_HOME%\style\crossQuery\resultFormatter\default\searchForms.xsl (1)

  2. Customization 1: remove the Search Proximity option

    a) Search for “Proximity” and note that it appears inside two separate

    elements, one creating the display with the select menu and one with the values expressed in a big statement. Delete the entire

    element in both instances.

    b) Save the file.

    c) Go to (or refresh) the Advanced search page in your browser to verify that “Proximity” is gone.

  3. Customization 2: make the Advanced Search form be the default

    a) Look at searchForms.xsl again. Near the top you’ll see this line indicating that the smode variable is defaulting to ‘simple’:

    <td class="{if(matches($smode,'simple')) then 'tab-select' else 'tab'}"><a href="search?smode=simple">Keyword</a></td>

    b) Changing that value requires determining where the variable is established. As mentioned above, searchForms.xsl is included by resultFormatter.xsl. Looking in the latter file, we don’t see any default for smode. However, resultFormatter.xsl also includes ..\common\resultFormatterCommon.xsl, which is where smode is defined.

    c) This code would be used by all applications driven by a shared XTF instance, so it is preferable to override the default by adding a parameter definition to resultFormatter.xsl, like this:

    <xsl:param select="’advanced’"/>
    

    Go ahead and make the change.

    d) Save the file.

    e) Go back to your browser and remove all parameters from your request, i.e., just go to http://localhost:8080/xtf/search. The default search form should now be “Advanced”.

Next tutorial step:

Exercise 6: Change the fields displayed in search results

Footnotes:
(1) The searchForms stylesheet is included by resultFormatter.xsl to handle the case where a search has not yet been specified by the user, causing the search form to appear.