Class InMemorySearchStore
java.lang.Object
io.fluxzero.sdk.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 Fluxzero Runtime connection is not available or needed.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static StringasIdentifier(String collection, String documentId) protected SerializedMessageasSerializedMessage(SerializedDocument document) bulkUpdate(Collection<DocumentUpdate> updates, Guarantee guarantee) Performs a batch update on a set of documents.voidclose()Closes any underlying resources.createAuditTrail(CreateAuditTrail request) Configures Fluxzero 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.booleanChecks whether a document with the given criteria exists.fetch(GetDocument r) Fetches a single serialized document matching the given request.fetch(GetDocuments request) Fetches a collection of serialized documents that match 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.move(SearchQuery query, String targetCollection, Guarantee guarantee) Moves documents matching a given query to the given target collection.Moves a document to another collection.protected voidnotifyMonitors(String collection, List<SerializedMessage> messages) openStream(String collection, Long lastIndex, int maxSize) protected voidpurgeExpiredMessages(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 voidstoreMessages(Map<String, SerializedDocument> updates) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface 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:SearchClientIndexes a list of serialized documents into the search engine.- Specified by:
indexin 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:SearchClientExecutes a streaming search query using the given criteria and fetch size.- Specified by:
searchin 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:SearchClientChecks whether a document with the given criteria exists.- Specified by:
documentExistsin interfaceSearchClient- Parameters:
r- an object describing the document (e.g., id and collection)- Returns:
trueif the document exists,falseotherwise
-
fetch
Description copied from interface:SearchClientFetches a single serialized document matching the given request.- Specified by:
fetchin interfaceSearchClient- Parameters:
r- an object describing the document to retrieve- Returns:
- an optional containing the document, if found
-
fetch
Description copied from interface:SearchClientFetches a collection of serialized documents that match the given request.- Specified by:
fetchin interfaceSearchClient- Parameters:
request- an object describing the documents to retrieve- Returns:
- a collection of retrieved documents matching
-
delete
Description copied from interface:SearchClientDeletes documents matching a given query.- Specified by:
deletein interfaceSearchClient- Parameters:
query- the search query specifying which documents to deleteguarantee- delivery guarantee- Returns:
- a future that completes when the deletion has been performed
-
move
public CompletableFuture<Void> move(SearchQuery query, String targetCollection, Guarantee guarantee) Description copied from interface:SearchClientMoves documents matching a given query to the given target collection.- Specified by:
movein interfaceSearchClient- Parameters:
query- the search query specifying which documents to movetargetCollection- the name of the collection to move documents toguarantee- delivery guarantee- Returns:
- a future that completes when the move has been performed
-
delete
Description copied from interface:SearchClientDeletes a document by its unique id and collection name.- Specified by:
deletein interfaceSearchClient- Parameters:
documentId- the document idcollection- the collection to delete fromguarantee- delivery guarantee- Returns:
- a future that completes when the deletion has been performed
-
move
public CompletableFuture<Void> move(String documentId, String collection, String targetCollection, Guarantee guarantee) Description copied from interface:SearchClientMoves a document to another collection.- Specified by:
movein interfaceSearchClient- Parameters:
documentId- the document idcollection- the collection to move fromtargetCollection- the collection to move toguarantee- delivery guarantee- Returns:
- a future that completes when the move has been performed
-
createAuditTrail
Description copied from interface:SearchClientConfigures Fluxzero to use a search collection as a searchable audit trail.- Specified by:
createAuditTrailin 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:SearchClientDeletes an entire document collection and all its contents.- Specified by:
deleteCollectionin 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:SearchClientRetrieves search statistics (counts, averages, etc.) over matching documents.- Specified by:
fetchStatisticsin 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:SearchClientFetches a histogram (bucketed time-series view) for documents matching the query.- Specified by:
fetchHistogramin interfaceSearchClient- Parameters:
request- the histogram query parameters- Returns:
- a
SearchHistogramrepresenting the result
-
fetchFacetStats
Description copied from interface:SearchClientRetrieves facet statistics (i.e., value counts) for a given query.- Specified by:
fetchFacetStatsin interfaceSearchClient- Parameters:
query- the query to match documents against- Returns:
- a list of facet statistics
-
bulkUpdate
Description copied from interface:SearchClientPerforms a batch update on a set of documents.- Specified by:
bulkUpdatein 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:SearchClientCloses any underlying resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceSearchClient
-