Package org.dlese.dpc.dds.action
Class DDSQueryAction
java.lang.Object
org.apache.struts.action.Action
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
FieldsModifier and TypeFieldDescriptionstatic final String[]A list of all fields that are indexed in encoded form via SimpleLuceneIndex.encodeToTerm()static final String[][]A list of aliases that map user-typed field names to the field name that exists in the index.static final intIndicates use of the AND boolean operator in thegetBooleanQuery(String[] terms, int operator, boolean useStemming)method.static final intIndicates use of the OR boolean operator in thegetBooleanQuery(String[] terms, int operator, boolean useStemming)method.static final String[]Identifiers that get printed in the query/search logsstatic final intIndicates web service search by client using general search requeststatic final intIndicates web service search by client using user search requeststatic final intIndicates an RSS general requeststatic final intIndicates histogram search by userstatic final intIndicates a JSHTML service searchstatic final intIndicates web service search by client using the ODL requeststatic final intIndicates textual search by userstatic final intIndicates whats new search by userstatic final intIndicates an RSS whats new requestFields inherited from class org.apache.struts.action.Action
defaultLocale, servlet -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final StringaddConstraintToQuery(String query, String constraintQuery) Adds a feature to the ConstraintToQuery attribute of the DDSQueryAction classstatic DDSStandardSearchResultddsStandardQuery(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.ActionForwardexecute(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 final StringBufferEncodes a query string such that each term that is part of a field that has been encoded in the index usingSimpleLuceneIndex.encodeToTerm() is replaced with the encoded form for searching.static final StringFormats 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 final StringgetBooleanQuery(String[] terms, int operator, boolean useStemming) Creates a boolean query string for use in the standard Lucene query parser.static StringGets the Lucene query string necessary to pull out records for a given collection.static org.apache.lucene.search.QuerygetGeospatialQuery(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 HashMapGets the stopWordMap attribute of the DDSQueryAction classstatic final StringgetVocabParamsQueryString(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 final org.apache.lucene.search.FiltergetWhatsNewDateFilter(String wnfrom, String wnto) Gets the whatsNewDateFilter attribute of the DDSQueryAction classorg.apache.struts.action.ActionForwardhandleMetadataSearchRequest(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 final booleanlogQuery(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 final StringSubstitutues the searchable field names for the common field names that user's may use in their query string.static voidsetDebug(boolean isDebugOutput) Sets the debug attribute of the DDSQueryAction classMethods 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
-
Field Details
-
OPERATOR_AND
public static final int OPERATOR_ANDIndicates use of the AND boolean operator in thegetBooleanQuery(String[] terms, int operator, boolean useStemming)method.- See Also:
-
OPERATOR_OR
public static final int OPERATOR_ORIndicates use of the OR boolean operator in thegetBooleanQuery(String[] terms, int operator, boolean useStemming)method.- See Also:
-
SEARCHTYPE_SEARCH
public static final int SEARCHTYPE_SEARCHIndicates textual search by user- See Also:
-
SEARCHTYPE_HISTOGRAM
public static final int SEARCHTYPE_HISTOGRAMIndicates histogram search by user- See Also:
-
SEARCHTYPE_WHATSNEW
public static final int SEARCHTYPE_WHATSNEWIndicates whats new search by user- See Also:
-
SEARCHTYPE_DDSWS_USER_SEARCH
public static final int SEARCHTYPE_DDSWS_USER_SEARCHIndicates web service search by client using user search request- See Also:
-
SEARCHTYPE_DDSWS_SEARCH
public static final int SEARCHTYPE_DDSWS_SEARCHIndicates web service search by client using general search request- See Also:
-
SEARCHTYPE_ODL_SEARCH
public static final int SEARCHTYPE_ODL_SEARCHIndicates web service search by client using the ODL request- See Also:
-
SEARCHTYPE_GENERAL_RSS
public static final int SEARCHTYPE_GENERAL_RSSIndicates an RSS general request- See Also:
-
SEARCHTYPE_WHATSNEW_RSS
public static final int SEARCHTYPE_WHATSNEW_RSSIndicates an RSS whats new request- See Also:
-
SEARCHTYPE_JSHTML_SEARCH
public static final int SEARCHTYPE_JSHTML_SEARCHIndicates a JSHTML service search- See Also:
-
SEARCH_TYPE_NAMES
Identifiers that get printed in the query/search logs -
ENCODED_FIELDS
A list of all fields that are indexed in encoded form via SimpleLuceneIndex.encodeToTerm() -
FIELD_ALIASES
A list of aliases that map user-typed field names to the field name that exists in the index.
-
-
Constructor Details
-
DDSQueryAction
public DDSQueryAction()
-
-
Method Details
-
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. ASimpleLuceneIndexmust be available to this class via a ServletContext attribute under the key "index." Returns anActionForwardinstance 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:
executein classorg.apache.struts.action.Action- Parameters:
mapping- The ActionMapping used to select this instanceform- The ActionForm for the given pagerequest- The HTTP request we are processingresponse- The HTTP response we are creating- Returns:
- The ActionForward instance describing where and how control should be forwarded
- Throws:
IOException- if an input/output error occursServletException- 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 instancequeryForm-request- The HTTP request we are processingresponse- The HTTP response we are creatingrm-- Returns:
- The ActionForward instance describing where and how control should be forwarded
- Throws:
IOException- if an input/output error occursServletException- 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 requestadditionalQueryOrConstraint- 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 itrm- The RepositoryManagervocab- The MetadataVocabcontext- The ServletContextsearchType- The searchType that gets logged- Returns:
- A DDSStandardSearchResult that contains the search results and a String indicating which page to forward to for presentataion.
-
addConstraintToQuery
Adds a feature to the ConstraintToQuery attribute of the DDSQueryAction class- Parameters:
query- The feature to be added to the ConstraintToQuery attributeconstraintQuery- 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 requestvocab- The metadata vocab useddocReaderAttributes- 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 datewnto- The to date- Returns:
- The whatsNewDateFilter value
- Throws:
ParseException- If error parsing
-
getCollectionQueryTerm
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
Gets the stopWordMap attribute of the DDSQueryAction class- Returns:
- The stopWordMap value
-
formatFieldsInQuery
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
Encodes a query string such that each term that is part of a field that has been encoded in the index usingSimpleLuceneIndex.encodeToTerm() is replaced with the encoded form for searching. May be used in conjuction withreplaceAliasedFieldNames(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
Substitutues the searchable field names for the common field names that user's may use in their query string. May be used in conjuction withformatEncodedFields(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
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 requestservletContext- The servletContextrequest- The HTTP requeststatusCode- The http status codecontentLen- The length of the data returned, in bytesnumSearchResults- The number of search results returned by the querytotalRecords- The total number of records in the system at the time of the queryrank- 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.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
-