Class QueryServlet

  • All Implemented Interfaces:
    Serializable, Servlet, ServletConfig

    public class QueryServlet
    extends VelocityViewServlet
    A query servlet.

    This class provides a basic servlet for searching a collection. It expects some data (a collection, an index map and a path) in the ServletContext (see the code for init()). It can be used to search in a collection, but it is essentially a worked-out example.

    The three parameters are q, the query, m, the maximum number of results to be displayed, and s, the first result to be displayed.

    Usually, the URI associated with each result is taken from the collection. Alternatively, each result will point to the /Item path with some query arguments (doc, containing the document pointer, uri, containing the original URI, and m, containing an optional suggested MIME type). See, for instance, GenericItem and InputStreamItem.

    The Velocity template used by this servlet can be set using the initialisation parameter template (or using a context attribute with the same name). If you're using this servlet via HttpQueryServer, please read the documentation therein for information about template resolution order.

    This servlet is thread safe. Each instance uses its own flyweight copies of the collection and query engine to return the result (in particular, snippets). In a production site it might be more sensible to pool and reuse such classes.

    Warning: the loadConfiguration(ServletConfig) method initialises Velocity with some default parameters: in particular, template resolution is performed first on the classpath, then relatively to the current directory, and finally using absolute pathnames. Watch out for template resolution issues.

    See Also:
    Serialized Form