Class InMemorySearchStore
java.lang.Object
io.fluxcapacitor.javaclient.persisting.search.client.InMemorySearchStore
- All Implemented Interfaces:
SearchClient
,AutoCloseable
In-memory implementation of the
SearchClient
, intended for local testing and development.
Stores all indexed documents in memory, with support for basic search, statistics, and deletion logic. Ideal for use in test scenarios where a real Flux platform connection is not available or needed.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static String
asIdentifier
(String collection, String documentId) protected SerializedMessage
asSerializedMessage
(SerializedDocument document) bulkUpdate
(Collection<DocumentUpdate> updates, Guarantee guarantee) Performs a batch update on a set of documents.void
close()
Closes any underlying resources.createAuditTrail
(CreateAuditTrail request) Configures Flux to use a search collection as a searchable audit trail.delete
(SearchQuery query, Guarantee guarantee) Deletes documents matching a given query.Deletes a document by its unique id and collection name.deleteCollection
(String collection, Guarantee guarantee) Deletes an entire document collection and all its contents.boolean
Checks whether a document with the given criteria exists.fetch
(GetDocument r) Fetches a single serialized document matching the given request.fetchFacetStats
(SearchQuery query) Retrieves facet statistics (i.e., value counts) for a given query.fetchHistogram
(GetSearchHistogram request) Fetches a histogram (bucketed time-series view) for documents matching the query.fetchStatistics
(SearchQuery query, List<String> fields, List<String> groupBy) Retrieves search statistics (counts, averages, etc.) over matching documents.index
(List<SerializedDocument> documents, Guarantee guarantee, boolean ifNotExists) Indexes a list of serialized documents into the search engine.protected void
notifyMonitors
(String collection, List<SerializedMessage> messages) openStream
(String collection, Long lastIndex, int maxSize) protected void
purgeExpiredMessages
(Duration messageExpiration) registerMonitor
(String collection, Consumer<List<SerializedMessage>> monitor) registerMonitor
(BiConsumer<String, List<SerializedMessage>> monitor) search
(SearchDocuments searchDocuments, int fetchSize) Executes a streaming search query using the given criteria and fetch size.protected void
storeMessages
(Map<String, SerializedDocument> updates) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.javaclient.persisting.search.client.SearchClient
deleteCollection
-
Field Details
-
identifier
-
-
Constructor Details
-
InMemorySearchStore
public InMemorySearchStore()
-
-
Method Details
-
asIdentifier
-
index
public CompletableFuture<Void> index(List<SerializedDocument> documents, Guarantee guarantee, boolean ifNotExists) Description copied from interface:SearchClient
Indexes a list of serialized documents into the search engine.- Specified by:
index
in interfaceSearchClient
- Parameters:
documents
- the documents to indexguarantee
- delivery guarantee (seeGuarantee
)ifNotExists
- iftrue
, only index documents that do not already exist- Returns:
- a future that completes when the operation is done
-
search
Description copied from interface:SearchClient
Executes a streaming search query using the given criteria and fetch size.- Specified by:
search
in interfaceSearchClient
- Parameters:
searchDocuments
- the search parameters and queryfetchSize
- the number of results to fetch per page- Returns:
- a stream of search hits matching the query
-
documentExists
Description copied from interface:SearchClient
Checks whether a document with the given criteria exists.- Specified by:
documentExists
in interfaceSearchClient
- Parameters:
r
- an object describing the document (e.g., id and collection)- Returns:
true
if the document exists,false
otherwise
-
fetch
Description copied from interface:SearchClient
Fetches a single serialized document matching the given request.- Specified by:
fetch
in interfaceSearchClient
- Parameters:
r
- an object describing the document to retrieve- Returns:
- an optional containing the document, if found
-
delete
Description copied from interface:SearchClient
Deletes documents matching a given query.- Specified by:
delete
in interfaceSearchClient
- Parameters:
query
- the search query specifying which documents to deleteguarantee
- delivery guarantee- Returns:
- a future that completes when the deletion has been performed
-
delete
Description copied from interface:SearchClient
Deletes a document by its unique id and collection name.- Specified by:
delete
in interfaceSearchClient
- Parameters:
documentId
- the document idcollection
- the collection to delete fromguarantee
- delivery guarantee- Returns:
- a future that completes when the deletion has been performed
-
createAuditTrail
Description copied from interface:SearchClient
Configures Flux to use a search collection as a searchable audit trail.- Specified by:
createAuditTrail
in interfaceSearchClient
- Parameters:
request
- a request object specifying the collection to use as an audit trail and retention configuration- Returns:
- a future that completes when the audit trail has been created.
-
deleteCollection
Description copied from interface:SearchClient
Deletes an entire document collection and all its contents.- Specified by:
deleteCollection
in interfaceSearchClient
- Parameters:
collection
- the name of the collection to deleteguarantee
- delivery guarantee- Returns:
- a future that completes when the collection has been deleted
-
fetchStatistics
public List<DocumentStats> fetchStatistics(SearchQuery query, List<String> fields, List<String> groupBy) Description copied from interface:SearchClient
Retrieves search statistics (counts, averages, etc.) over matching documents.- Specified by:
fetchStatistics
in interfaceSearchClient
- Parameters:
query
- the query to filter documentsfields
- the fields to compute statistics forgroupBy
- field names used to group statistics- Returns:
- a list of
DocumentStats
-
fetchHistogram
Description copied from interface:SearchClient
Fetches a histogram (bucketed time-series view) for documents matching the query.- Specified by:
fetchHistogram
in interfaceSearchClient
- Parameters:
request
- the histogram query parameters- Returns:
- a
SearchHistogram
representing the result
-
fetchFacetStats
Description copied from interface:SearchClient
Retrieves facet statistics (i.e., value counts) for a given query.- Specified by:
fetchFacetStats
in interfaceSearchClient
- Parameters:
query
- the query to match documents against- Returns:
- a list of facet statistics
-
bulkUpdate
Description copied from interface:SearchClient
Performs a batch update on a set of documents.- Specified by:
bulkUpdate
in interfaceSearchClient
- Parameters:
updates
- the update operations to performguarantee
- delivery guarantee- Returns:
- a future that completes when the updates have been applied
-
openStream
-
storeMessages
-
asSerializedMessage
-
purgeExpiredMessages
-
notifyMonitors
-
registerMonitor
-
registerMonitor
-
close
public void close()Description copied from interface:SearchClient
Closes any underlying resources.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceSearchClient
-