DLESE Tools
v1.6.0

org.dlese.dpc.dds.action
Class DDSQueryAction

java.lang.Object
  extended by org.apache.struts.action.Action
      extended by org.dlese.dpc.dds.action.DDSQueryAction

public final class DDSQueryAction
extends org.apache.struts.action.Action

A Struts Action for handling display of resource record descriptions, and their various collection info.

Author:
John Weatherley, Ryan Deardorff

Field Summary
static String[] ENCODED_FIELDS
          A list of all fields that are indexed in encoded form via SimpleLuceneIndex.encodeToTerm()
static String[][] FIELD_ALIASES
          A list of aliases that map user-typed field names to the field name that exists in the index.
static int OPERATOR_AND
          Indicates use of the AND boolean operator in the getBooleanQuery(String[] terms, int operator, boolean useStemming) method.
static int OPERATOR_OR
          Indicates use of the OR boolean operator in the getBooleanQuery(String[] terms, int operator, boolean useStemming) method.
static String[] SEARCH_TYPE_NAMES
          Identifiers that get printed in the query/search logs
static int SEARCHTYPE_DDSWS_SEARCH
          Indicates web service search by client using general search request
static int SEARCHTYPE_DDSWS_USER_SEARCH
          Indicates web service search by client using user search request
static int SEARCHTYPE_GENERAL_RSS
          Indicates an RSS general request
static int SEARCHTYPE_HISTOGRAM
          Indicates histogram search by user
static int SEARCHTYPE_JSHTML_SEARCH
          Indicates a JSHTML service search
static int SEARCHTYPE_ODL_SEARCH
          Indicates web service search by client using the ODL request
static int SEARCHTYPE_SEARCH
          Indicates textual search by user
static int SEARCHTYPE_WHATSNEW
          Indicates whats new search by user
static int SEARCHTYPE_WHATSNEW_RSS
          Indicates an RSS whats new request
 
Fields inherited from class org.apache.struts.action.Action
defaultLocale, servlet
 
Constructor Summary
DDSQueryAction()
           
 
Method Summary
static String addConstraintToQuery(String query, String constraintQuery)
          Adds a feature to the ConstraintToQuery attribute of the DDSQueryAction class
static DDSStandardSearchResult ddsStandardQuery(HttpServletRequest request, String additionalQueryOrConstraint, RepositoryManager rm, MetadataVocab vocab, ServletContext context, int searchType)
          Performs textual and field-based searches limited to discoverable items only and using pre-defined search logic.
 org.apache.struts.action.ActionForward execute(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, HttpServletRequest request, HttpServletResponse response)
          Processes the specified HTTP request and creates the corresponding HTTP response by forwarding to a JSP that will create it.
static StringBuffer formatEncodedFields(String q)
          Encodes a query string such that each term that is part of a field that has been encoded in the index using SimpleLuceneIndex.encodeToTerm() is replaced with the encoded form for searching.
static String formatFieldsInQuery(String q)
          Formats the fields/terms in the query string by replacing the aliased field names and encoding terms that are in fields that have been indexed encoded.
static String getBooleanQuery(String[] terms, int operator, boolean useStemming)
          Creates a boolean query string for use in the standard Lucene query parser.
static String getCollectionQueryTerm(String ky)
          Gets the Lucene query string necessary to pull out records for a given collection.
static org.apache.lucene.search.Query getGeospatialQuery(HttpServletRequest request)
          Generates a geospatial bounding box Lucene Query from the necessary parameteres in an http request, which are geoPredicate, geoBBNorth, geoBBWest, geoBBEast, geoBBSouth.
static HashMap getStopWordMap()
          Gets the stopWordMap attribute of the DDSQueryAction class
static String getVocabParamsQueryString(HttpServletRequest request, MetadataVocab vocab, HashMap docReaderAttributes)
          Gets a query that limits a search to vocab-managed fields such as gradeRange (gr), resourceType (re), subject (su), contentStandard (cs) and collection (ky).
static org.apache.lucene.search.Filter getWhatsNewDateFilter(String wnfrom, String wnto)
          Gets the whatsNewDateFilter attribute of the DDSQueryAction class
 org.apache.struts.action.ActionForward handleMetadataSearchRequest(org.apache.struts.action.ActionMapping mapping, DDSQueryForm queryForm, HttpServletRequest request, HttpServletResponse response, RepositoryManager rm)
          Handle a request to search over metadata collections and forwared to the appropriate jsp page to render the response.
static boolean logQuery(String query, ServletContext servletContext, HttpServletRequest request, int statusCode, int contentLen, int numSearchResults, int totalRecords, int rank, int searchType)
          This method must be called at just after the user's query has been processed by Lucene.
static String replaceAliasedFieldNames(String q)
          Substitutues the searchable field names for the common field names that user's may use in their query string.
static void setDebug(boolean isDebugOutput)
          Sets the debug attribute of the DDSQueryAction class
 
Methods inherited from class org.apache.struts.action.Action
addErrors, addMessages, execute, generateToken, getDataSource, getDataSource, getErrors, getLocale, getMessages, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, resetToken, saveErrors, saveErrors, saveErrors, saveMessages, saveMessages, saveToken, setLocale, setServlet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPERATOR_AND

public static final int OPERATOR_AND
Indicates use of the AND boolean operator in the getBooleanQuery(String[] terms, int operator, boolean useStemming) method.

See Also:
Constant Field Values

OPERATOR_OR

public static final int OPERATOR_OR
Indicates use of the OR boolean operator in the getBooleanQuery(String[] terms, int operator, boolean useStemming) method.

See Also:
Constant Field Values

SEARCHTYPE_SEARCH

public static final int SEARCHTYPE_SEARCH
Indicates textual search by user

See Also:
Constant Field Values

SEARCHTYPE_HISTOGRAM

public static final int SEARCHTYPE_HISTOGRAM
Indicates histogram search by user

See Also:
Constant Field Values

SEARCHTYPE_WHATSNEW

public static final int SEARCHTYPE_WHATSNEW
Indicates whats new search by user

See Also:
Constant Field Values

SEARCHTYPE_DDSWS_USER_SEARCH

public static final int SEARCHTYPE_DDSWS_USER_SEARCH
Indicates web service search by client using user search request

See Also:
Constant Field Values

SEARCHTYPE_DDSWS_SEARCH

public static final int SEARCHTYPE_DDSWS_SEARCH
Indicates web service search by client using general search request

See Also:
Constant Field Values

SEARCHTYPE_ODL_SEARCH

public static final int SEARCHTYPE_ODL_SEARCH
Indicates web service search by client using the ODL request

See Also:
Constant Field Values

SEARCHTYPE_GENERAL_RSS

public static final int SEARCHTYPE_GENERAL_RSS
Indicates an RSS general request

See Also:
Constant Field Values

SEARCHTYPE_WHATSNEW_RSS

public static final int SEARCHTYPE_WHATSNEW_RSS
Indicates an RSS whats new request

See Also:
Constant Field Values

SEARCHTYPE_JSHTML_SEARCH

public static final int SEARCHTYPE_JSHTML_SEARCH
Indicates a JSHTML service search

See Also:
Constant Field Values

SEARCH_TYPE_NAMES

public static final String[] SEARCH_TYPE_NAMES
Identifiers that get printed in the query/search logs


ENCODED_FIELDS

public static final String[] ENCODED_FIELDS
A list of all fields that are indexed in encoded form via SimpleLuceneIndex.encodeToTerm()


FIELD_ALIASES

public static final String[][] FIELD_ALIASES
A list of aliases that map user-typed field names to the field name that exists in the index.

Constructor Detail

DDSQueryAction

public DDSQueryAction()
Method Detail

execute

public org.apache.struts.action.ActionForward execute(org.apache.struts.action.ActionMapping mapping,
                                                      org.apache.struts.action.ActionForm form,
                                                      HttpServletRequest request,
                                                      HttpServletResponse response)
                                               throws IOException,
                                                      ServletException
Processes the specified HTTP request and creates the corresponding HTTP response by forwarding to a JSP that will create it. A SimpleLuceneIndex must be available to this class via a ServletContext attribute under the key "index." Returns an ActionForward instance that maps to the Struts forwarding name "simple.query," which must be configured in struts-config.xml to forward to the JSP page that will handle the request.

Overrides:
execute in class org.apache.struts.action.Action
Parameters:
mapping - The ActionMapping used to select this instance
request - The HTTP request we are processing
response - The HTTP response we are creating
form - The ActionForm for the given page
Returns:
The ActionForward instance describing where and how control should be forwarded
Throws:
IOException - if an input/output error occurs
ServletException - if a servlet exception occurs

handleMetadataSearchRequest

public org.apache.struts.action.ActionForward handleMetadataSearchRequest(org.apache.struts.action.ActionMapping mapping,
                                                                          DDSQueryForm queryForm,
                                                                          HttpServletRequest request,
                                                                          HttpServletResponse response,
                                                                          RepositoryManager rm)
                                                                   throws IOException,
                                                                          ServletException
Handle a request to search over metadata collections and forwared to the appropriate jsp page to render the response.

Parameters:
mapping - The ActionMapping used to select this instance
request - The HTTP request we are processing
response - The HTTP response we are creating
rm -
queryForm -
Returns:
The ActionForward instance describing where and how control should be forwarded
Throws:
IOException - if an input/output error occurs
ServletException - if a servlet exception occurs

ddsStandardQuery

public static DDSStandardSearchResult ddsStandardQuery(HttpServletRequest request,
                                                       String additionalQueryOrConstraint,
                                                       RepositoryManager rm,
                                                       MetadataVocab vocab,
                                                       ServletContext context,
                                                       int searchType)
Performs textual and field-based searches limited to discoverable items only and using pre-defined search logic. Used by DDS search and DDSWebServices search.

Parameters:
request - The HTTP request
rm - The RepositoryManager
vocab - The MetadataVocab
context - The ServletContext
searchType - The searchType that gets logged
additionalQueryOrConstraint - If the q parameter is empty, this value will be used as the search query, if q is not empty this value will be ANDed with it
Returns:
A DDSStandardSearchResult that contains the search results and a String indicating which page to forward to for presentataion.

addConstraintToQuery

public static final String addConstraintToQuery(String query,
                                                String constraintQuery)
Adds a feature to the ConstraintToQuery attribute of the DDSQueryAction class

Parameters:
query - The feature to be added to the ConstraintToQuery attribute
constraintQuery - The feature to be added to the ConstraintToQuery attribute
Returns:
The resulting query

getGeospatialQuery

public static org.apache.lucene.search.Query getGeospatialQuery(HttpServletRequest request)
                                                         throws Exception
Generates a geospatial bounding box Lucene Query from the necessary parameteres in an http request, which are geoPredicate, geoBBNorth, geoBBWest, geoBBEast, geoBBSouth. If the query crosses the 180/-180 longitude it is split into two query regions, one on each side, joined by boolean clause.

Parameters:
request - An http request that may contain geospatial parameters
Returns:
A geospatial Query, or null if no no geospatial parameters were supplied
Throws:
Exception - If there is an error with one or more of the geospatial parameters

getVocabParamsQueryString

public static final String getVocabParamsQueryString(HttpServletRequest request,
                                                     MetadataVocab vocab,
                                                     HashMap docReaderAttributes)
Gets a query that limits a search to vocab-managed fields such as gradeRange (gr), resourceType (re), subject (su), contentStandard (cs) and collection (ky). The query returned begins with AND. If no sucy parameters exist in the request, returns an empty String.

Parameters:
request - The HTTP request
vocab - The metadata vocab used
docReaderAttributes - The doc reader attributes
Returns:
Gets a query that limits a search to vocab-managed fields, or an empty String if no such field parameters exist in the request.

getWhatsNewDateFilter

public static final org.apache.lucene.search.Filter getWhatsNewDateFilter(String wnfrom,
                                                                          String wnto)
                                                                   throws ParseException
Gets the whatsNewDateFilter attribute of the DDSQueryAction class

Parameters:
wnfrom - The from date
wnto - The to date
Returns:
The whatsNewDateFilter value
Throws:
ParseException - If error parsing

getCollectionQueryTerm

public static String getCollectionQueryTerm(String ky)
Gets the Lucene query string necessary to pull out records for a given collection. This method maps the query to the set of records that belong to the collection. This value may be ANDed with others to produce a compound boolean query.

Parameters:
ky - The vocab key, for example 06
Returns:
The query String

getStopWordMap

public static HashMap getStopWordMap()
Gets the stopWordMap attribute of the DDSQueryAction class

Returns:
The stopWordMap value

formatFieldsInQuery

public static final String formatFieldsInQuery(String q)
Formats the fields/terms in the query string by replacing the aliased field names and encoding terms that are in fields that have been indexed encoded.

Parameters:
q - The raw query by user
Returns:
Formatted query

formatEncodedFields

public static final StringBuffer formatEncodedFields(String q)
Encodes a query string such that each term that is part of a field that has been encoded in the index using SimpleLuceneIndex.encodeToTerm() is replaced with the encoded form for searching. May be used in conjuction with replaceAliasedFieldNames(String).

Examples:

'id:DLESE-000-000-000-001' becomes 'id:dlesex45000x45000x45000x45001'

'ocean AND urlenc:(http://*.noaa.gov* OR http://*.nasa.gov*)' becomes 'ocean AND urlenc:(httpx58x47x47*x46noaax46gov* OR httpx58x47x47*x46nasax46gov*)'

Parameters:
q - A query string
Returns:
An query string with appropriate terms encoded

replaceAliasedFieldNames

public static final String replaceAliasedFieldNames(String q)
Substitutues the searchable field names for the common field names that user's may use in their query string. May be used in conjuction with formatEncodedFields(String).

Examples:

'url:http://*.noaa.gov*' becomes 'urlenc:http://*.noaa.gov*'

Parameters:
q - A query from a user
Returns:
The query with the aliased field names replaced

getBooleanQuery

public static final String getBooleanQuery(String[] terms,
                                           int operator,
                                           boolean useStemming)
Creates a boolean query string for use in the standard Lucene query parser.

Parameters:
terms - The terms used in the query.
operator - The operator to use (AND|OR).
useStemming - True to stem the tersm, false to leave unchanged.
Returns:
A formatted boolean query or null if no terms were present.

logQuery

public static final boolean logQuery(String query,
                                     ServletContext servletContext,
                                     HttpServletRequest request,
                                     int statusCode,
                                     int contentLen,
                                     int numSearchResults,
                                     int totalRecords,
                                     int rank,
                                     int searchType)
This method must be called at just after the user's query has been processed by Lucene. It is used to log user queries.

Parameters:
query - The text query entered by the user or submitted by the web service client, or null if none was submitted with the request
statusCode - The http status code
contentLen - The length of the data returned, in bytes
numSearchResults - The number of search results returned by the query
totalRecords - The total number of records in the system at the time of the query
rank - The rank of the item(s) retunred on the page. If this is a results page, then this is rank of the first item on the page.
servletContext - The servletContext
request - The HTTP request
searchType - The search type (search, histogram, what's new, ws-uql, ws-lql, etc)
Returns:
True iff successful, else false

setDebug

public static void setDebug(boolean isDebugOutput)
Sets the debug attribute of the DDSQueryAction class

Parameters:
isDebugOutput - The new debug value

DLESE Tools
v1.6.0