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 Details

    • 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:
    • 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:
    • SEARCHTYPE_HISTOGRAM

      public static final int SEARCHTYPE_HISTOGRAM
      Indicates histogram search by user
      See Also:
    • SEARCHTYPE_WHATSNEW

      public static final int SEARCHTYPE_WHATSNEW
      Indicates whats new search by user
      See Also:
    • SEARCHTYPE_GENERAL_RSS

      public static final int SEARCHTYPE_GENERAL_RSS
      Indicates an RSS general request
      See Also:
    • SEARCHTYPE_WHATSNEW_RSS

      public static final int SEARCHTYPE_WHATSNEW_RSS
      Indicates an RSS whats new request
      See Also:
    • 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 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. 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
      form - The ActionForm for the given page
      request - The HTTP request we are processing
      response - 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 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
      queryForm -
      request - The HTTP request we are processing
      response - The HTTP response we are creating
      rm -
      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
      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
      rm - The RepositoryManager
      vocab - The MetadataVocab
      context - The ServletContext
      searchType - 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

      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
      servletContext - The servletContext
      request - The HTTP 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.
      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