Sun ONE Web Server 6.1 Getting Started Guide |
Chapter 5
Making Content SearchableIn this chapter we’ll see how we can make content searchable on a virtual server. Sun ONE Web Server 6.1 includes a search engine that allows users to search documents on the server and display results on a web page. It provides a default search web application which you can enable or disable on a specific virtual server. This search application provides the basic web pages used to query collections and view results.
Before we can enable search on a virtual server, we must first ensure that Java is enabled for the virtual server class that contains the virtual server. Java is enabled by default and you can enable/disable it per server instance in Sun ONE Web Server 6.1 The Java tab for the virtual server contains a link, the Enable/Disable Java link, that takes you to a page which allows you to enable or disable Java.
Next, because searches require a database of searchable documents (called a collection) against which users can search, you need to create this database. At a minimum, you must have at least one collection configured on your server. You can however create as many collections as required.
Let’s walk though a few basic search-related tasks:
Create a Search Collection
Let’s say you want to create a collection called “HR” on your virtual server acme. To do so, you use the Create Collection page in the Search tab of your virtual server.
In the figure above, we’ve specified certain parameters that will define our collection.
- /hr/publish/info is the directory from which documents will be indexed by the collection. By default, only the directory designated as the document root directory for the virtual server is listed for selection. To add a directory to the list of indexable directories, you must create additional document directories, as discussed in "Create an Additional Document Directory."
- “HR” is the collection name. The server uses this internally to refer to the collection.
- “HR Docs” is the display name. This is what end users will see as the name of the collection in the search query page. If we’d left this field blank, the collection name “HR”, would appear on the search query page.
- *.html as the value of the Pattern field indicates that only files with a .html extension will be indexed.
- We’ve left the Encoding field as is. This means that the default encoding, “ISO-8859-1” will be used. If, for instance, the documents you want to index are in Japanese, you might use an appropriate encoding, say, “Shift_JIS.”
You need to save and apply your changes after you’re done for the changes to take effect.
You may update any of the parameters in the search collections you have created at any time using the Update Collection link on the Search tab of the virtual server.
Now that we’ve created our collection, we need to keep some additional points in mind.
Update Your Collection
When you add new documents to the /hr/publish/info folder, you must update the “HR” collection to index the new documents into the collection. You can do so manually using the Update Collections page.
However, if your site is constantly being updated, you might want to schedule regular maintenance tasks on the collection. You might for example, wish to update your collections at the end of the day when you know that new documents are likely to have been added.
To automate maintenance tasks on collections, use the Add Scheduled Maintenance link in the Search tab of the virtual server. Choose Update as the type of task you want to automate, and specify other parameters as appropriate, for example, the time of day to perform the task, the day(s) of the week to perform the task, and so on, as shown below:
Enable the Search Application
Next, we need to enable the search application on the virtual server using the Search Configuration link in the Search tab of the virtual server.
If you’re planning on using the default search application, all you need to do is to click the Enabled checkbox on this page and use the default values for the rest of the parameters.
To view the search query page, enter the following address on a browser window:
http://acme/search
Customize the Search Application
Finally, you may choose to customize the search application to suit your specific needs. You can use the JSP tag libraries included with Sun ONE Web Server 6.1 to do so. Take a look at the default search application located at server_root/bin/https/webapps/search as a sample application that illustrates the use of customizable search tags. The section Customizing Search Pages in the Sun ONE Web Server 6.1 Administrator’s Guide provides examples of customizing the search page, for example, by having the query form appear on a side bar of the page or search results appear differently.
For a detailed description of the JSP search tags you can use, refer to the Sun ONE Web Server 6.1 Programmer’s Guide to Web Applications.