it.unimi.di.mg4j.query
Class QueryServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.apache.velocity.tools.view.servlet.VelocityViewServlet
              extended by it.unimi.di.mg4j.query.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

Field Summary
protected static String DEFAULT_TEMPLATE
          The default Velocity template used by this servlet; may be overriden in the context using an attribute named template.
protected  DocumentCollection documentCollection
          The document collection.
protected  Object2ReferenceMap<String,Index> indexMap
          A sorted map from index names to indices: the first entry is the default index.
protected  QueryEngine queryEngine
          The query engine.
protected  String template
          The actual template used by this servlet (default: DEFAULT_TEMPLATE).
protected  List<CharSequence> titleList
          An optional title list if the document collection is not present.
 
Fields inherited from class org.apache.velocity.tools.view.servlet.VelocityViewServlet
CONTENT_TYPE, DEFAULT_CONTENT_TYPE, DEFAULT_OUTPUT_ENCODING, DEFAULT_PROPERTIES_PATH, DEFAULT_TOOLBOX_PATH, DEFAULT_TOOLS_PROPERTIES, INIT_PROPS_KEY, SERVLET_CONTEXT_KEY, TOOLBOX_KEY, toolboxManager
 
Constructor Summary
QueryServlet()
           
 
Method Summary
 Template handleRequest(HttpServletRequest request, HttpServletResponse response, Context context)
           
 void init()
           
protected  ExtendedProperties loadConfiguration(ServletConfig config)
           
 
Methods inherited from class org.apache.velocity.tools.view.servlet.VelocityViewServlet
createContext, doGet, doPost, doRequest, error, findInitParameter, getResponseWriter, getTemplate, getTemplate, getVelocityEngine, getVelocityProperty, init, initToolbox, initVelocity, mergeTemplate, performMerge, requestCleanup, setContentType, setVelocityEngine
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TEMPLATE

protected static final String DEFAULT_TEMPLATE
The default Velocity template used by this servlet; may be overriden in the context using an attribute named template.

See Also:
Constant Field Values

template

protected String template
The actual template used by this servlet (default: DEFAULT_TEMPLATE).


queryEngine

protected QueryEngine queryEngine
The query engine.


documentCollection

protected DocumentCollection documentCollection
The document collection.


titleList

protected List<CharSequence> titleList
An optional title list if the document collection is not present.


indexMap

protected Object2ReferenceMap<String,Index> indexMap
A sorted map from index names to indices: the first entry is the default index.

Constructor Detail

QueryServlet

public QueryServlet()
Method Detail

loadConfiguration

protected ExtendedProperties loadConfiguration(ServletConfig config)
                                        throws FileNotFoundException,
                                               IOException
Overrides:
loadConfiguration in class VelocityViewServlet
Throws:
FileNotFoundException
IOException

init

public void init()
          throws ServletException
Overrides:
init in class GenericServlet
Throws:
ServletException

handleRequest

public Template handleRequest(HttpServletRequest request,
                              HttpServletResponse response,
                              Context context)
Overrides:
handleRequest in class VelocityViewServlet