Class QueryServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- org.apache.velocity.tools.view.servlet.VelocityViewServlet
-
- it.unimi.di.big.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 forinit()). 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,
GenericItemandInputStreamItem.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
Fields Modifier and Type Field Description protected static StringDEFAULT_TEMPLATEThe default Velocity template used by this servlet; may be overriden in the context using an attribute named template.protected DocumentCollectiondocumentCollectionThe document collection.protected Object2ReferenceMap<String,Index>indexMapA sorted map from index names to indices: the first entry is the default index.protected QueryEnginequeryEngineThe query engine.protected StringtemplateThe actual template used by this servlet (default:DEFAULT_TEMPLATE).protected BigList<? extends CharSequence>titleListAn 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
Constructors Constructor Description QueryServlet()
-
Method Summary
Modifier and Type Method Description TemplatehandleRequest(HttpServletRequest request, HttpServletResponse response, Context context)voidinit()protected org.apache.commons.collections.ExtendedPropertiesloadConfiguration(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
-
-
-
-
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 BigList<? extends 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.
-
-
Method Detail
-
loadConfiguration
protected org.apache.commons.collections.ExtendedProperties loadConfiguration(ServletConfig config) throws FileNotFoundException, IOException
- Overrides:
loadConfigurationin classVelocityViewServlet- Throws:
FileNotFoundExceptionIOException
-
init
public void init() throws ServletException- Overrides:
initin classGenericServlet- Throws:
ServletException
-
handleRequest
public Template handleRequest(HttpServletRequest request, HttpServletResponse response, Context context)
- Overrides:
handleRequestin classVelocityViewServlet
-
-