Package org.codelibs.fess.helper
Class IndexingHelper
java.lang.Object
org.codelibs.fess.helper.IndexingHelper
Helper class for indexing operations in the Fess search engine.
This class provides functionality for sending documents to the search engine,
managing document lifecycle operations (create, update, delete), and handling
thumbnail processing during indexing.
The IndexingHelper manages bulk operations, handles retries on failures, and provides various query-based operations for document management. It also integrates with the thumbnail generation system and handles the cleanup of old documents during updates.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intDefault number of rows to process in a single batchprotected intMaximum number of retry attempts for failed operationsprotected longInterval between requests in milliseconds -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongcalculateDocumentSize(Map<String, Object> dataMap) Calculates the memory size of a document data map.longdeleteByConfigId(String configId) Deletes all documents associated with the specified configuration ID.longdeleteByConfigId(SearchEngineClient searchEngineClient, String index, String configId) Deletes all documents associated with the specified configuration ID from the given index.protected longdeleteByQueryBuilder(SearchEngineClient searchEngineClient, String index, org.opensearch.index.query.QueryBuilder queryBuilder) Deletes documents using the specified query builder and refreshes the index.longdeleteBySessionId(String sessionId) Deletes all documents associated with the specified session ID.longdeleteBySessionId(SearchEngineClient searchEngineClient, String index, String sessionId) Deletes all documents associated with the specified session ID from the given index.longdeleteByVirtualHost(String virtualHost) Deletes all documents associated with the specified virtual host.longdeleteByVirtualHost(SearchEngineClient searchEngineClient, String index, String virtualHost) Deletes all documents associated with the specified virtual host from the given index.longdeleteChildDocument(SearchEngineClient searchEngineClient, String id) Deletes all child documents that belong to the specified parent document.booleandeleteDocument(SearchEngineClient searchEngineClient, String id) Deletes a document from the search index by its ID.protected longdeleteDocumentByQuery(SearchEngineClient searchEngineClient, String index, org.opensearch.index.query.QueryBuilder queryBuilder) Deletes all documents that match the specified query from the specified index.longdeleteDocumentByQuery(SearchEngineClient searchEngineClient, org.opensearch.index.query.QueryBuilder queryBuilder) Deletes all documents that match the specified query from the default update index.longdeleteDocumentByUrl(SearchEngineClient searchEngineClient, String url) Deletes all documents that match the specified URL.longdeleteDocumentsByDocId(SearchEngineClient searchEngineClient, List<String> docIdList) Deletes all documents that match the specified document IDs.protected longdeleteOldDocuments(SearchEngineClient searchEngineClient, DocList docList) Deletes old documents that have the same URL but different document IDs as the documents in the provided list.getChildDocumentList(SearchEngineClient searchEngineClient, String id, String[] fields) Retrieves all child documents that belong to the specified parent document.getDocument(SearchEngineClient searchEngineClient, String id, String[] fields) Retrieves a document from the search index by its ID.getDocumentListByPrefixId(SearchEngineClient searchEngineClient, String id, String[] fields) Retrieves a list of documents whose IDs start with the specified prefix.getDocumentListByQuery(SearchEngineClient searchEngineClient, org.opensearch.index.query.QueryBuilder queryBuilder, String[] fields) Retrieves a list of documents that match the specified query.protected longgetDocumentSizeByQuery(SearchEngineClient searchEngineClient, org.opensearch.index.query.QueryBuilder queryBuilder, org.codelibs.fess.mylasta.direction.FessConfig fessConfig) Gets the total number of documents that match the specified query.protected intrefreshIndex(SearchEngineClient searchEngineClient, String index) Refreshes the specified index to make recent changes visible for search.voidsendDocuments(SearchEngineClient searchEngineClient, DocList docList) Sends a list of documents to the search engine for indexing.voidsetDefaultRowSize(int defaultRowSize) Sets the default number of rows to process in a single batch.voidsetMaxRetryCount(int maxRetryCount) Sets the maximum number of retry attempts for failed operations.voidsetRequestInterval(long requestInterval) Sets the interval between requests in milliseconds.booleanupdateDocument(SearchEngineClient searchEngineClient, String id, String field, Object value) Updates a specific field of a document in the search index.
-
Field Details
-
maxRetryCount
protected int maxRetryCountMaximum number of retry attempts for failed operations -
defaultRowSize
protected int defaultRowSizeDefault number of rows to process in a single batch -
requestInterval
protected long requestIntervalInterval between requests in milliseconds
-
-
Constructor Details
-
IndexingHelper
public IndexingHelper()Default constructor for indexing helper. Creates a new instance with default values.
-
-
Method Details
-
sendDocuments
Sends a list of documents to the search engine for indexing. This method handles thumbnail processing, deletes old documents with the same URL, and performs bulk indexing operations with proper error handling.- Parameters:
searchEngineClient- the search engine client to use for indexingdocList- the list of documents to be indexed- Throws:
SearchEngineClientException- if the bulk indexing operation fails
-
deleteOldDocuments
Deletes old documents that have the same URL but different document IDs as the documents in the provided list. This prevents duplicate documents from accumulating in the index.- Parameters:
searchEngineClient- the search engine client to use for deletiondocList- the list of new documents to check against- Returns:
- the number of old documents that were deleted
-
updateDocument
public boolean updateDocument(SearchEngineClient searchEngineClient, String id, String field, Object value) Updates a specific field of a document in the search index.- Parameters:
searchEngineClient- the search engine client to use for the updateid- 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
-
deleteDocument
Deletes a document from the search index by its ID.- Parameters:
searchEngineClient- the search engine client to use for deletionid- the document ID to delete- Returns:
- true if the deletion was successful, false otherwise
-
deleteDocumentByUrl
Deletes all documents that match the specified URL.- Parameters:
searchEngineClient- the search engine client to use for deletionurl- the URL to match for document deletion- Returns:
- the number of documents that were deleted
-
deleteDocumentsByDocId
Deletes all documents that match the specified document IDs.- Parameters:
searchEngineClient- the search engine client to use for deletiondocIdList- the list of document IDs to delete- Returns:
- the number of documents that were deleted
-
deleteDocumentByQuery
public long deleteDocumentByQuery(SearchEngineClient searchEngineClient, org.opensearch.index.query.QueryBuilder queryBuilder) Deletes all documents that match the specified query from the default update index.- Parameters:
searchEngineClient- the search engine client to use for deletionqueryBuilder- the query to match documents for deletion- Returns:
- the number of documents that were deleted
-
deleteDocumentByQuery
protected long deleteDocumentByQuery(SearchEngineClient searchEngineClient, String index, org.opensearch.index.query.QueryBuilder queryBuilder) Deletes all documents that match the specified query from the specified index.- Parameters:
searchEngineClient- the search engine client to use for deletionindex- the index name to delete documents fromqueryBuilder- the query to match documents for deletion- Returns:
- the number of documents that were deleted
-
getDocument
public Map<String,Object> getDocument(SearchEngineClient searchEngineClient, String id, String[] fields) Retrieves a document from the search index by its ID.- Parameters:
searchEngineClient- the search engine client to use for retrievalid- the document ID to retrievefields- the fields to include in the response (null for all fields)- Returns:
- the document as a map of field names to values, or null if not found
-
getDocumentListByPrefixId
public List<Map<String,Object>> getDocumentListByPrefixId(SearchEngineClient searchEngineClient, String id, String[] fields) Retrieves a list of documents whose IDs start with the specified prefix.- Parameters:
searchEngineClient- the search engine client to use for retrievalid- the ID prefix to match documentsfields- the fields to include in the response (null for all fields)- Returns:
- a list of documents that match the prefix
-
deleteChildDocument
Deletes all child documents that belong to the specified parent document.- Parameters:
searchEngineClient- the search engine client to use for deletionid- the parent document ID whose children should be deleted- Returns:
- the number of child documents that were deleted
-
getChildDocumentList
public List<Map<String,Object>> getChildDocumentList(SearchEngineClient searchEngineClient, String id, String[] fields) Retrieves all child documents that belong to the specified parent document.- Parameters:
searchEngineClient- the search engine client to use for retrievalid- the parent document ID whose children should be retrievedfields- the fields to include in the response (null for all fields)- Returns:
- a list of child documents
-
getDocumentListByQuery
protected List<Map<String,Object>> getDocumentListByQuery(SearchEngineClient searchEngineClient, org.opensearch.index.query.QueryBuilder queryBuilder, String[] fields) Retrieves a list of documents that match the specified query. This method handles large result sets by using scroll search when necessary and enforces maximum document size limits.- Parameters:
searchEngineClient- the search engine client to use for retrievalqueryBuilder- the query to match documentsfields- the fields to include in the response (null for all fields)- Returns:
- a list of documents that match the query
-
getDocumentSizeByQuery
protected long getDocumentSizeByQuery(SearchEngineClient searchEngineClient, org.opensearch.index.query.QueryBuilder queryBuilder, org.codelibs.fess.mylasta.direction.FessConfig fessConfig) Gets the total number of documents that match the specified query.- Parameters:
searchEngineClient- the search engine client to use for the countqueryBuilder- the query to count documents forfessConfig- the Fess configuration- Returns:
- the number of documents that match the query
-
deleteBySessionId
Deletes all documents associated with the specified session ID.- Parameters:
sessionId- the session ID to delete documents for- Returns:
- the number of documents that were deleted
-
deleteBySessionId
public long deleteBySessionId(SearchEngineClient searchEngineClient, String index, String sessionId) Deletes all documents associated with the specified session ID from the given index.- Parameters:
searchEngineClient- the search engine client to use for deletionindex- the index name to delete documents fromsessionId- the session ID to delete documents for- Returns:
- the number of documents that were deleted
-
deleteByConfigId
Deletes all documents associated with the specified configuration ID.- Parameters:
configId- the configuration ID to delete documents for- Returns:
- the number of documents that were deleted
-
deleteByConfigId
Deletes all documents associated with the specified configuration ID from the given index.- Parameters:
searchEngineClient- the search engine client to use for deletionindex- the index name to delete documents fromconfigId- the configuration ID to delete documents for- Returns:
- the number of documents that were deleted
-
deleteByVirtualHost
Deletes all documents associated with the specified virtual host.- Parameters:
virtualHost- the virtual host to delete documents for- Returns:
- the number of documents that were deleted
-
deleteByVirtualHost
public long deleteByVirtualHost(SearchEngineClient searchEngineClient, String index, String virtualHost) Deletes all documents associated with the specified virtual host from the given index.- Parameters:
searchEngineClient- the search engine client to use for deletionindex- the index name to delete documents fromvirtualHost- the virtual host to delete documents for- Returns:
- the number of documents that were deleted
-
deleteByQueryBuilder
protected long deleteByQueryBuilder(SearchEngineClient searchEngineClient, String index, org.opensearch.index.query.QueryBuilder queryBuilder) Deletes documents using the specified query builder and refreshes the index. This method first refreshes the index, then performs the deletion, and logs the result.- Parameters:
searchEngineClient- the search engine client to use for deletionindex- the index name to delete documents fromqueryBuilder- the query to match documents for deletion- Returns:
- the number of documents that were deleted
-
refreshIndex
Refreshes the specified index to make recent changes visible for search. This operation ensures that all pending writes are persisted and searchable.- Parameters:
searchEngineClient- the search engine client to use for refreshindex- the index name to refresh- Returns:
- the refresh status code
-
calculateDocumentSize
Calculates the memory size of a document data map. This is useful for monitoring memory usage during indexing operations.- Parameters:
dataMap- the document data as a map of field names to values- Returns:
- the estimated memory size in bytes
-
setMaxRetryCount
public void setMaxRetryCount(int maxRetryCount) Sets the maximum number of retry attempts for failed operations.- Parameters:
maxRetryCount- the maximum retry count
-
setDefaultRowSize
public void setDefaultRowSize(int defaultRowSize) Sets the default number of rows to process in a single batch.- Parameters:
defaultRowSize- the default row size
-
setRequestInterval
public void setRequestInterval(long requestInterval) Sets the interval between requests in milliseconds.- Parameters:
requestInterval- the request interval in milliseconds
-