Class SearchHelper

java.lang.Object
org.codelibs.fess.helper.SearchHelper

public class SearchHelper extends Object
Helper class for handling search operations in Fess. This class provides comprehensive search functionality including document search, scroll search, and bulk operations. It handles search request parameter processing, query building, response formatting, and search log management. Key features: - Document search with pagination and faceting - Scroll search for large result sets - Document retrieval by ID - Bulk document updates - Search parameter serialization/deserialization for cookies - Integration with search engines and logging systems
  • Field Details

    • searchRequestParamsRewriters

      protected SearchHelper.SearchRequestParamsRewriter[] searchRequestParamsRewriters
      Array of search request parameter rewriters for modifying search parameters.
    • mapper

      protected com.fasterxml.jackson.databind.ObjectMapper mapper
      Jackson ObjectMapper for JSON serialization/deserialization.
  • Constructor Details

    • SearchHelper

      public SearchHelper()
      Default constructor for creating a new SearchHelper instance.
  • Method Details

    • search

      public void search(SearchRequestParams searchRequestParams, SearchRenderData data, org.dbflute.optional.OptionalThing<org.codelibs.fess.mylasta.action.FessUserBean> userBean)
      Performs a search operation and populates the search render data with results. This method handles the complete search workflow including parameter processing, query execution, result formatting, and logging. It supports automatic retry with escaped queries if the initial search fails.
      Parameters:
      searchRequestParams - The search request parameters
      data - The search render data to populate with results
      userBean - Optional user information for permission checking
    • searchInternal

      protected List<Map<String,Object>> searchInternal(String query, SearchRequestParams params, org.dbflute.optional.OptionalThing<org.codelibs.fess.mylasta.action.FessUserBean> userBean)
      Internal search method that executes the actual search query. This method performs the search using the rank fusion processor and may retry with OR operator if the hit count is below the configured minimum threshold.
      Parameters:
      query - The search query string
      params - The search request parameters
      userBean - Optional user information for permission checking
      Returns:
      List of search result documents
    • scrollSearch

      public long scrollSearch(SearchRequestParams params, BooleanFunction<Map<String,Object>> cursor, org.dbflute.optional.OptionalThing<org.codelibs.fess.mylasta.action.FessUserBean> userBean)
      Performs a scroll search for processing large result sets efficiently. This method uses OpenSearch scroll API to iterate through large numbers of documents without loading them all into memory at once.
      Parameters:
      params - The search request parameters
      cursor - Function to process each document in the result set
      userBean - Optional user information for permission checking
      Returns:
      Total number of documents processed
    • deleteByQuery

      public long deleteByQuery(jakarta.servlet.http.HttpServletRequest request, SearchRequestParams params)
      Deletes documents matching the specified search parameters.
      Parameters:
      request - The HTTP servlet request
      params - The search request parameters to identify documents to delete
      Returns:
      Number of documents deleted
    • getLanguages

      public String[] getLanguages(jakarta.servlet.http.HttpServletRequest request, SearchRequestParams params)
      Extracts and normalizes language preferences from request parameters or browser locale. This method prioritizes explicit language parameters over browser locale settings and handles special cases like "all languages" selection.
      Parameters:
      request - The HTTP servlet request
      params - The search request parameters
      Returns:
      Array of normalized language codes
    • getDocumentByDocId

      public org.dbflute.optional.OptionalEntity<Map<String,Object>> getDocumentByDocId(String docId, String[] fields, org.dbflute.optional.OptionalThing<org.codelibs.fess.mylasta.action.FessUserBean> userBean)
      Retrieves a single document by its document ID.
      Parameters:
      docId - The document ID to retrieve
      fields - Array of field names to include in the result
      userBean - Optional user information for permission checking
      Returns:
      Optional entity containing the document data if found
    • getDocumentListByDocIds

      public List<Map<String,Object>> getDocumentListByDocIds(String[] docIds, String[] fields, org.dbflute.optional.OptionalThing<org.codelibs.fess.mylasta.action.FessUserBean> userBean, SearchRequestParams.SearchRequestType searchRequestType)
      Retrieves multiple documents by their document IDs.
      Parameters:
      docIds - Array of document IDs to retrieve
      fields - Array of field names to include in the results
      userBean - Optional user information for permission checking
      searchRequestType - Type of search request for role-based access control
      Returns:
      List of document data maps
    • update

      public boolean update(String id, String field, Object value)
      Updates a single field of a document.
      Parameters:
      id - The document ID to update
      field - The field name to update
      value - The new value for the field
      Returns:
      true if the update was successful, false otherwise
    • update

      public boolean update(String id, Consumer<org.opensearch.action.update.UpdateRequestBuilder> builderLambda)
      Updates a document using a custom update request builder.
      Parameters:
      id - The document ID to update
      builderLambda - Consumer function to configure the update request builder
      Returns:
      true if the update was successful, false otherwise
    • bulkUpdate

      public boolean bulkUpdate(Consumer<org.opensearch.action.bulk.BulkRequestBuilder> consumer)
      Performs bulk update operations using a custom bulk request builder.
      Parameters:
      consumer - Consumer function to configure the bulk request builder
      Returns:
      true if all bulk operations were successful, false otherwise
      Throws:
      org.codelibs.core.exception.InterruptedRuntimeException - if the operation is interrupted
      SearchEngineClientException - if the bulk update fails
    • rewrite

      protected SearchRequestParams rewrite(SearchRequestParams params)
      Applies registered parameter rewriters to modify search request parameters.
      Parameters:
      params - The original search request parameters
      Returns:
      Modified search request parameters after applying all rewriters
    • addRewriter

      public void addRewriter(SearchHelper.SearchRequestParamsRewriter rewriter)
      Adds a search request parameter rewriter to the list of active rewriters.
      Parameters:
      rewriter - The parameter rewriter to add
    • storeSearchParameters

      public void storeSearchParameters()
      Stores current search parameters in a browser cookie for later retrieval. This method serializes the current request parameters, compresses them using GZIP, encodes them with Base64, and stores them in a secure HTTP cookie.
    • serializeParameters

      protected String serializeParameters(RequestParameter[] parameters)
      Serializes request parameters to a compressed and encoded string.
      Parameters:
      parameters - Array of request parameters to serialize
      Returns:
      Base64-encoded, GZIP-compressed JSON string of parameters
      Throws:
      SearchQueryException - if serialization fails
    • gzipCompress

      protected byte[] gzipCompress(byte[] data)
      Compresses data using GZIP compression.
      Parameters:
      data - The data to compress
      Returns:
      GZIP-compressed data
      Throws:
      org.codelibs.core.exception.IORuntimeException - if compression fails
    • getSearchParameters

      public RequestParameter[] getSearchParameters()
      Retrieves and deserializes search parameters from browser cookies.
      Returns:
      Array of request parameters from the cookie, or empty array if none found
    • gzipDecompress

      protected byte[] gzipDecompress(byte[] compressed)
      Decompresses GZIP-compressed data.
      Parameters:
      compressed - The GZIP-compressed data to decompress
      Returns:
      Decompressed data
      Throws:
      org.codelibs.core.exception.IORuntimeException - if decompression fails
    • isSearchParameterCookieSecure

      protected boolean isSearchParameterCookieSecure(jakarta.servlet.http.HttpServletRequest request)
      Determines if the search parameter cookie should be secure based on configuration and request.
      Parameters:
      request - The HTTP request
      Returns:
      true if the cookie should have the secure flag set