Package org.codelibs.fess.helper
Class SearchHelper
java.lang.Object
org.codelibs.fess.helper.SearchHelper
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface for rewriting search request parameters. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected com.fasterxml.jackson.databind.ObjectMapperJackson ObjectMapper for JSON serialization/deserialization.protected SearchHelper.SearchRequestParamsRewriter[]Array of search request parameter rewriters for modifying search parameters. -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor for creating a new SearchHelper instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a search request parameter rewriter to the list of active rewriters.booleanbulkUpdate(Consumer<org.opensearch.action.bulk.BulkRequestBuilder> consumer) Performs bulk update operations using a custom bulk request builder.longdeleteByQuery(jakarta.servlet.http.HttpServletRequest request, SearchRequestParams params) Deletes documents matching the specified search parameters.getDocumentByDocId(String docId, String[] fields, org.dbflute.optional.OptionalThing<org.codelibs.fess.mylasta.action.FessUserBean> userBean) Retrieves a single document by its document ID.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.String[]getLanguages(jakarta.servlet.http.HttpServletRequest request, SearchRequestParams params) Extracts and normalizes language preferences from request parameters or browser locale.Retrieves and deserializes search parameters from browser cookies.protected byte[]gzipCompress(byte[] data) Compresses data using GZIP compression.protected byte[]gzipDecompress(byte[] compressed) Decompresses GZIP-compressed data.protected booleanisSearchParameterCookieSecure(jakarta.servlet.http.HttpServletRequest request) Determines if the search parameter cookie should be secure based on configuration and request.protected SearchRequestParamsrewrite(SearchRequestParams params) Applies registered parameter rewriters to modify search request parameters.longscrollSearch(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.voidsearch(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.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.protected StringserializeParameters(RequestParameter[] parameters) Serializes request parameters to a compressed and encoded string.voidStores current search parameters in a browser cookie for later retrieval.booleanUpdates a single field of a document.booleanUpdates a document using a custom update request builder.
-
Field Details
-
searchRequestParamsRewriters
Array of search request parameter rewriters for modifying search parameters. -
mapper
protected com.fasterxml.jackson.databind.ObjectMapper mapperJackson 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 parametersdata- The search render data to populate with resultsuserBean- 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 stringparams- The search request parametersuserBean- 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 parameterscursor- Function to process each document in the result setuserBean- 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 requestparams- 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 requestparams- 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 retrievefields- Array of field names to include in the resultuserBean- 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 retrievefields- Array of field names to include in the resultsuserBean- Optional user information for permission checkingsearchRequestType- Type of search request for role-based access control- Returns:
- List of document data maps
-
update
Updates a single field of a document.- Parameters:
id- The document ID to updatefield- The field name to updatevalue- 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 updatebuilderLambda- Consumer function to configure the update request builder- Returns:
- true if the update was successful, false otherwise
-
bulkUpdate
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 interruptedSearchEngineClientException- if the bulk update fails
-
rewrite
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
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
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
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
-