|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.servlet.GenericServlet javax.servlet.http.HttpServlet org.apache.velocity.tools.view.servlet.VelocityViewServlet it.unimi.di.mg4j.query.QueryServlet
public class QueryServlet
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.
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 |
---|
protected static final String DEFAULT_TEMPLATE
protected String template
DEFAULT_TEMPLATE
).
protected QueryEngine queryEngine
protected DocumentCollection documentCollection
protected List<CharSequence> titleList
protected Object2ReferenceMap<String,Index> indexMap
Constructor Detail |
---|
public QueryServlet()
Method Detail |
---|
protected ExtendedProperties loadConfiguration(ServletConfig config) throws FileNotFoundException, IOException
loadConfiguration
in class VelocityViewServlet
FileNotFoundException
IOException
public void init() throws ServletException
init
in class GenericServlet
ServletException
public Template handleRequest(HttpServletRequest request, HttpServletResponse response, Context context)
handleRequest
in class VelocityViewServlet
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |