com.iphrase.onestep.beans
Class QueryHandler

java.lang.Object
  |
  +--com.iphrase.onestep.beans.QueryHandler

public class QueryHandler
extends java.lang.Object

QueryHandler provides high-level access to the OneStep Runtime API Query object.

The following is an example of using QueryHandler directly to set a hidden constraint on every query:

 <%@ page import="com.iphrase.runtime.query.constraint.*" %>
 <%
 QueryHandler queryHandler = new QueryHandler(); 
 QueryHandler.initializeWithPageContext(pageContext);

 // add hidden constraint every time
 String[] values = {"foo", "bar"};
 Constraint c = new Enumerated.InList("some_feature", values); 
 c.setHidden();
 QueryHandler.getRuntimeQuery().getConstraints().merge(new Disjunction(c));

 queryHandler.execute();
 %>
 

There are three important steps that QueryHandler performs when processing each search request:
1. Provide connection parameters required for communication with the OneStep server. The OneStep server address is obtained using one of the following:

2. Extract search parameters from the HttpServletRequest object and provide them as an input to the OneStep server.

3. Receive search results from the OneStep server and prepare them so that they are easily accessible from the JSP code. For this purpose, QueryHandler builds and stores the following variables in the request-scope:


Constructor Summary
QueryHandler()
          Construct a new (i.e., empty and uninitialized) QueryHandler instance.
 
Method Summary
 void addServerAddress(java.lang.String address)
          Sets a single OneStep server address in the following format onestep_host:onestep_port.
 java.lang.String decodeInputParameter(java.lang.String paramName)
          Returns the URL-decoded value of a request parameter as a String, or null if the parameter does not exist.
 void execute()
          Executes the OneStep Runtime API Query instance and stores the results it receives in the request-scope for the remainder of the page.
 java.lang.String getLayout()
          Get the layout name to be used for the results rendering.
 java.lang.String getLayoutFileName()
          Get the layout file name to be used for the results rendering.
 com.iphrase.runtime.query.result.QueryResult getQueryResult()
          Get the query results returned by the OneStep server.
 com.iphrase.runtime.Connector getRuntimeConnector()
          Get the OneStep Runtime API Connector object created by this handler.
 com.iphrase.runtime.query.Query getRuntimeQuery()
          Get the OneStep Runtime API Query object created by this handler.
 boolean initializeWithPageContext(javax.servlet.jsp.PageContext pageContext)
          Initialize this QueryHandler instance with the servlet page context.
 void setRetry(float retrySecs)
          The setter for the optional retry attribute.
 void setTimeout(float secs)
          The setter for the optional timeout attribute.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryHandler

public QueryHandler()
Construct a new (i.e., empty and uninitialized) QueryHandler instance.
Method Detail

initializeWithPageContext

public boolean initializeWithPageContext(javax.servlet.jsp.PageContext pageContext)
                                  throws javax.servlet.jsp.JspException
Initialize this QueryHandler instance with the servlet page context. This includes initialization and request parameters.
Throws:
javax.servlet.jsp.JspException -  

execute

public void execute()
             throws javax.servlet.jsp.JspException
Executes the OneStep Runtime API Query instance and stores the results it receives in the request-scope for the remainder of the page.
Throws:
javax.servlet.jsp.JspException -  

getQueryResult

public com.iphrase.runtime.query.result.QueryResult getQueryResult()
Get the query results returned by the OneStep server.
Returns:
QueryResult instance

getLayout

public java.lang.String getLayout()
Get the layout name to be used for the results rendering.
Returns:
layout name or null if layout name not available

getLayoutFileName

public java.lang.String getLayoutFileName()
Get the layout file name to be used for the results rendering.
Returns:
layout file name or null if layout name not available

getRuntimeConnector

public com.iphrase.runtime.Connector getRuntimeConnector()
Get the OneStep Runtime API Connector object created by this handler.
Returns:
Connector

getRuntimeQuery

public com.iphrase.runtime.query.Query getRuntimeQuery()
Get the OneStep Runtime API Query object created by this handler.
Returns:
Query instance

setRetry

public void setRetry(float retrySecs)
The setter for the optional retry attribute. Pass value of -1 if you want a "dead" server to be immediately available for the next retry.
Parameters:
retrySeconds - wait before retrying a "dead" iPhrase server

setTimeout

public void setTimeout(float secs)
The setter for the optional timeout attribute.
Parameters:
secs - specifies the maximal number of seconds to wait for the OneStep server response.

addServerAddress

public void addServerAddress(java.lang.String address)
Sets a single OneStep server address in the following format onestep_host:onestep_port.
Parameters:
address - single server address.

decodeInputParameter

public java.lang.String decodeInputParameter(java.lang.String paramName)
Returns the URL-decoded value of a request parameter as a String, or null if the parameter does not exist.
Parameters:
a - String specifying the name of the parameter
Returns:
URL-decoded value

© Copyright 2005, 2006. IBM Corporation. All rights reserved.