Class InMemorySearchStore

java.lang.Object
io.fluxzero.sdk.persisting.search.client.InMemorySearchStore
All Implemented Interfaces:
SearchClient, AutoCloseable

public class InMemorySearchStore extends Object implements SearchClient
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. Document updates are retained for later readers even when no monitor is registered, subject to retention and replacement by a newer update for the same document.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Resolves the exact current-document collection for model IDs.
    static interface 
    Resolves explicitly placed current child edges for root models.
    static interface 
    Resolves target model IDs from related matches at the current relationship boundary.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final Function<io.fluxzero.common.api.search.SerializedDocument, String>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
     
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    adoptModelMigration(io.fluxzero.common.api.search.AdoptModelMigration request)
    Atomically adopts a previously inspected and application-verified staged Model document while retaining the accepted normalized source until an ordinary Model write ends legacy-write coexistence.
    protected static String
    asIdentifier(String collection, String documentId)
     
    protected io.fluxzero.common.api.SerializedMessage
    asSerializedMessage(io.fluxzero.common.api.search.SerializedDocument document)
     
    bulkUpdate(Collection<io.fluxzero.common.api.search.DocumentUpdate> updates, io.fluxzero.common.Guarantee guarantee)
    Performs a batch update on a set of documents.
    void
    Closes any underlying resources.
    createAuditTrail(io.fluxzero.common.api.search.CreateAuditTrail request)
    Configures Fluxzero to use a search collection as a searchable audit trail.
    delete(io.fluxzero.common.api.search.SearchQuery query, io.fluxzero.common.Guarantee guarantee, int batchSize)
    Deletes documents matching a given query using the requested batch size.
    delete(String documentId, String collection, io.fluxzero.common.Guarantee guarantee)
    Deletes a document by its unique id and collection name.
    deleteCollection(String collection, io.fluxzero.common.Guarantee guarantee)
    Deletes an entire document collection and all its contents.
    boolean
    documentExists(io.fluxzero.common.api.search.HasDocument r)
    Checks whether a document with the given criteria exists.
    void
    eraseModels(Set<String> modelIds)
    Removes storage owned by hard-erased Models, retaining independently indexed read models with coincidental IDs.
    Optional<io.fluxzero.common.api.search.SerializedDocument>
    fetch(io.fluxzero.common.api.search.GetDocument r)
    Fetches a single serialized document matching the given request.
    Collection<io.fluxzero.common.api.search.SerializedDocument>
    fetch(io.fluxzero.common.api.search.GetDocuments request)
    Fetches a collection of serialized documents that match the given request.
    List<io.fluxzero.common.api.search.FacetStats>
    fetchFacetStats(io.fluxzero.common.api.search.SearchQuery query)
    Retrieves facet statistics (i.e., value counts) for a given query.
    io.fluxzero.common.api.search.SearchHistogram
    fetchHistogram(io.fluxzero.common.api.search.GetSearchHistogram request)
    Fetches a histogram (bucketed time-series view) for documents matching the query.
    io.fluxzero.common.api.search.GetDocumentResult
    fetchModelDocument(io.fluxzero.common.api.search.GetDocument request)
    Fetches a direct Model document together with the durable head written by the same materialization transaction.
    List<io.fluxzero.common.api.search.DocumentStats>
    fetchStatistics(io.fluxzero.common.api.search.SearchQuery query, List<String> fields, List<String> groupBy)
    Retrieves search statistics (counts, averages, etc.) over matching documents.
    io.fluxzero.common.api.search.GetModelMigrationResult
    getModelMigration(io.fluxzero.common.api.search.GetModelMigration request)
    Retrieves the production and staged direct documents used to verify one Model migration.
    io.fluxzero.common.api.search.GetModelMigrationsResult
    getModelMigrations(io.fluxzero.common.api.search.GetModelMigrations request)
    Retrieves a bounded batch of staged direct Model migrations.
    List<io.fluxzero.common.api.search.SearchCollection>
    Retrieves existing regular search collections and audit trails.
    index(List<io.fluxzero.common.api.search.SerializedDocument> documents, io.fluxzero.common.Guarantee guarantee, boolean ifNotExists)
    Indexes a list of serialized documents into the search engine.
    void
    materializeModelCommit(io.fluxzero.common.api.modeling.CommitModels commit, List<io.fluxzero.common.api.modeling.ModelUpdate> assignedUpdates, Set<String> excludedModelIds)
    Prepares and executes document materialization for the assigned Model commit, excluding the supplied Model identifiers.
    void
    materializeModelGraphProjection(io.fluxzero.common.api.modeling.ModelGraphProjectionConfiguration configuration, Set<String> rootIds, long stateIndex, boolean rebuild)
    Synchronously materializes affected roots for the SDK-only graph-projection worker.
    move(io.fluxzero.common.api.search.SearchQuery query, String targetCollection, io.fluxzero.common.Guarantee guarantee)
    Moves documents matching a given query to the given target collection.
    move(String documentId, String collection, String targetCollection, io.fluxzero.common.Guarantee guarantee)
    Moves a document to another collection.
    protected void
    notifyMonitors(String collection, List<io.fluxzero.common.api.SerializedMessage> messages)
     
    Stream<io.fluxzero.common.api.SerializedMessage>
    openStream(String collection, Long lastIndex, int maxSize)
    Returns up to maxSize document messages after lastIndex, excluding tombstones; a null index starts from the beginning and an unknown collection yields an empty stream.
    Stream<io.fluxzero.common.api.SerializedMessage>
    openStream(String collection, Long lastIndex, int maxSize, boolean includeDocumentTombstones)
    Returns up to maxSize document messages after lastIndex, optionally including tombstones.
    prepareModelCommit(io.fluxzero.common.api.modeling.CommitModels commit, List<io.fluxzero.common.api.modeling.ModelUpdate> assignedUpdates, Set<String> excludedModelIds)
    Materializes direct Model documents and returns their deferred local-monitor publication.
    prepareModelGraphProjection(io.fluxzero.common.api.modeling.ModelGraphProjectionConfiguration configuration, Set<String> rootIds, long stateIndex, boolean rebuild)
    Materializes graph documents and returns their deferred local-monitor publication.
    prepareModelGraphSchemaProjection(io.fluxzero.common.api.modeling.ModelGraphProjectionConfiguration configuration, Set<String> rootIds, long stateIndex)
    Re-materializes only affected roots at the same business boundary after a source schema rewrite.
    protected void
    purgeExpiredMessages(Duration messageExpiration)
     
    io.fluxzero.common.Registration
    registerMonitor(String collection, Consumer<List<io.fluxzero.common.api.SerializedMessage>> monitor)
    Registers a monitor restricted to the supplied collection and returns a registration that removes it.
    io.fluxzero.common.Registration
    registerMonitor(BiConsumer<String, List<io.fluxzero.common.api.SerializedMessage>> monitor)
    Registers a monitor for updates across collections and returns a registration that removes it.
    rewriteModelGraphDocument(io.fluxzero.common.api.search.SerializedDocument replacement, String expectedManifest, io.fluxzero.common.Guarantee guarantee)
    Conditionally replaces one materialized model-graph document while its manifest still matches the handled version.
    rewriteModelSourceDocument(io.fluxzero.common.api.search.RewriteModelSourceDocument request)
    Atomically rewrites a verified internal source at the same Model head and document proof.
    Stream<SearchHit<io.fluxzero.common.api.search.SerializedDocument>>
    search(io.fluxzero.common.api.search.SearchDocuments searchDocuments, int fetchSize)
    Executes a streaming search query using the given criteria and fetch size.
    Stream<SearchHit<io.fluxzero.common.api.search.SerializedDocument>>
    searchModelGraph(io.fluxzero.common.api.search.SearchModelGraphDocuments request, int fetchSize)
    Executes a current-state model search and composes each matching root's explicitly placed child graph.
    Stream<SearchHit<io.fluxzero.common.api.search.SerializedDocument>>
    searchModels(io.fluxzero.common.api.search.SearchModelDocuments request, int fetchSize)
    Executes a bounded current-state search across independent model relationships.
    void
    Binds schema rewrites to retained work for individual Model nodes.
    void
    Binds schema-only source rewrites to the local worker's retained rebuild requests.
    protected void
    storeMessages(Map<String, io.fluxzero.common.api.search.SerializedDocument> updates)
     
    void
    Removes the collection's documents, indices, message log, and audit trail, then notifies its monitors with an empty batch.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • identifier

      protected static final Function<io.fluxzero.common.api.search.SerializedDocument, String> identifier
  • Constructor Details

  • Method Details

    • asIdentifier

      protected static String asIdentifier(String collection, String documentId)
    • getSearchCollections

      public List<io.fluxzero.common.api.search.SearchCollection> getSearchCollections()
      Description copied from interface: SearchClient
      Retrieves existing regular search collections and audit trails.

      Implementations predating this operation may throw UnsupportedOperationException.

      Specified by:
      getSearchCollections in interface SearchClient
      Returns:
      the available collections with their storage types, in deterministic order
    • index

      public CompletableFuture<Void> index(List<io.fluxzero.common.api.search.SerializedDocument> documents, io.fluxzero.common.Guarantee guarantee, boolean ifNotExists)
      Description copied from interface: SearchClient
      Indexes a list of serialized documents into the search engine.
      Specified by:
      index in interface SearchClient
      Parameters:
      documents - the documents to index
      guarantee - delivery guarantee (see Guarantee)
      ifNotExists - if true, only index documents that do not already exist
      Returns:
      a future that completes according to the selected delivery guarantee
    • search

      public Stream<SearchHit<io.fluxzero.common.api.search.SerializedDocument>> search(io.fluxzero.common.api.search.SearchDocuments searchDocuments, int fetchSize)
      Description copied from interface: SearchClient
      Executes a streaming search query using the given criteria and fetch size.
      Specified by:
      search in interface SearchClient
      Parameters:
      searchDocuments - the search parameters and query
      fetchSize - the number of results to fetch per page
      Returns:
      a stream of search hits matching the query
    • searchModels

      public Stream<SearchHit<io.fluxzero.common.api.search.SerializedDocument>> searchModels(io.fluxzero.common.api.search.SearchModelDocuments request, int fetchSize)
      Description copied from interface: SearchClient
      Executes a bounded current-state search across independent model relationships.
      Specified by:
      searchModels in interface SearchClient
    • searchModelGraph

      public Stream<SearchHit<io.fluxzero.common.api.search.SerializedDocument>> searchModelGraph(io.fluxzero.common.api.search.SearchModelGraphDocuments request, int fetchSize)
      Description copied from interface: SearchClient
      Executes a current-state model search and composes each matching root's explicitly placed child graph.
      Specified by:
      searchModelGraph in interface SearchClient
    • documentExists

      public boolean documentExists(io.fluxzero.common.api.search.HasDocument r)
      Description copied from interface: SearchClient
      Checks whether a document with the given criteria exists.
      Specified by:
      documentExists in interface SearchClient
      Parameters:
      r - an object describing the document (e.g., id and collection)
      Returns:
      true if the document exists, false otherwise
    • fetch

      public Optional<io.fluxzero.common.api.search.SerializedDocument> fetch(io.fluxzero.common.api.search.GetDocument r)
      Description copied from interface: SearchClient
      Fetches a single serialized document matching the given request.
      Specified by:
      fetch in interface SearchClient
      Parameters:
      r - an object describing the document to retrieve
      Returns:
      an optional containing the document, if found
    • fetchModelDocument

      public io.fluxzero.common.api.search.GetDocumentResult fetchModelDocument(io.fluxzero.common.api.search.GetDocument request)
      Description copied from interface: SearchClient
      Fetches a direct Model document together with the durable head written by the same materialization transaction.
      Specified by:
      fetchModelDocument in interface SearchClient
    • setModelSchemaInvalidation

      public void setModelSchemaInvalidation(Consumer<String> listener)
      Binds schema-only source rewrites to the local worker's retained rebuild requests.
    • setModelNodeSchemaInvalidation

      public void setModelNodeSchemaInvalidation(BiConsumer<String,String> listener)
      Binds schema rewrites to retained work for individual Model nodes.
    • rewriteModelSourceDocument

      public CompletableFuture<Void> rewriteModelSourceDocument(io.fluxzero.common.api.search.RewriteModelSourceDocument request)
      Description copied from interface: SearchClient
      Atomically rewrites a verified internal source at the same Model head and document proof.
      Specified by:
      rewriteModelSourceDocument in interface SearchClient
    • getModelMigration

      public io.fluxzero.common.api.search.GetModelMigrationResult getModelMigration(io.fluxzero.common.api.search.GetModelMigration request)
      Description copied from interface: SearchClient
      Retrieves the production and staged direct documents used to verify one Model migration.
      Specified by:
      getModelMigration in interface SearchClient
    • getModelMigrations

      public io.fluxzero.common.api.search.GetModelMigrationsResult getModelMigrations(io.fluxzero.common.api.search.GetModelMigrations request)
      Description copied from interface: SearchClient
      Retrieves a bounded batch of staged direct Model migrations.
      Specified by:
      getModelMigrations in interface SearchClient
    • adoptModelMigration

      public CompletableFuture<Void> adoptModelMigration(io.fluxzero.common.api.search.AdoptModelMigration request)
      Description copied from interface: SearchClient
      Atomically adopts a previously inspected and application-verified staged Model document while retaining the accepted normalized source until an ordinary Model write ends legacy-write coexistence.
      Specified by:
      adoptModelMigration in interface SearchClient
    • fetch

      public Collection<io.fluxzero.common.api.search.SerializedDocument> fetch(io.fluxzero.common.api.search.GetDocuments request)
      Description copied from interface: SearchClient
      Fetches a collection of serialized documents that match the given request.
      Specified by:
      fetch in interface SearchClient
      Parameters:
      request - an object describing the documents to retrieve
      Returns:
      a collection of retrieved documents matching
    • delete

      public CompletableFuture<Void> delete(io.fluxzero.common.api.search.SearchQuery query, io.fluxzero.common.Guarantee guarantee, int batchSize)
      Description copied from interface: SearchClient
      Deletes documents matching a given query using the requested batch size.

      A value of 0 uses the runtime default, a positive value requests that batch size, and a negative value requests a single unbounded statement.

      Specified by:
      delete in interface SearchClient
      Parameters:
      query - the search query specifying which documents to delete
      guarantee - delivery guarantee
      batchSize - requested delete batch size
      Returns:
      a future that completes when the selected delivery guarantee is reached
    • move

      public CompletableFuture<Void> move(io.fluxzero.common.api.search.SearchQuery query, String targetCollection, io.fluxzero.common.Guarantee guarantee)
      Description copied from interface: SearchClient
      Moves documents matching a given query to the given target collection.
      Specified by:
      move in interface SearchClient
      Parameters:
      query - the search query specifying which documents to move
      targetCollection - the name of the collection to move documents to
      guarantee - delivery guarantee
      Returns:
      a future that completes when the selected delivery guarantee is reached
    • delete

      public CompletableFuture<Void> delete(String documentId, String collection, io.fluxzero.common.Guarantee guarantee)
      Description copied from interface: SearchClient
      Deletes a document by its unique id and collection name.
      Specified by:
      delete in interface SearchClient
      Parameters:
      documentId - the document id
      collection - the collection to delete from
      guarantee - delivery guarantee
      Returns:
      a future that completes when the selected delivery guarantee is reached
    • rewriteModelGraphDocument

      public CompletableFuture<Void> rewriteModelGraphDocument(io.fluxzero.common.api.search.SerializedDocument replacement, String expectedManifest, io.fluxzero.common.Guarantee guarantee)
      Description copied from interface: SearchClient
      Conditionally replaces one materialized model-graph document while its manifest still matches the handled version. Implementations without durable model-graph projections may retain the unsupported default.
      Specified by:
      rewriteModelGraphDocument in interface SearchClient
    • move

      public CompletableFuture<Void> move(String documentId, String collection, String targetCollection, io.fluxzero.common.Guarantee guarantee)
      Description copied from interface: SearchClient
      Moves a document to another collection.
      Specified by:
      move in interface SearchClient
      Parameters:
      documentId - the document id
      collection - the collection to move from
      targetCollection - the collection to move to
      guarantee - delivery guarantee
      Returns:
      a future that completes when the selected delivery guarantee is reached
    • createAuditTrail

      public CompletableFuture<Void> createAuditTrail(io.fluxzero.common.api.search.CreateAuditTrail request)
      Description copied from interface: SearchClient
      Configures Fluxzero to use a search collection as a searchable audit trail.
      Specified by:
      createAuditTrail in interface SearchClient
      Parameters:
      request - a request object specifying the collection to use as an audit trail and retention configuration
      Returns:
      a future that completes according to the selected delivery guarantee
    • deleteCollection

      public CompletableFuture<Void> deleteCollection(String collection, io.fluxzero.common.Guarantee guarantee)
      Description copied from interface: SearchClient
      Deletes an entire document collection and all its contents.
      Specified by:
      deleteCollection in interface SearchClient
      Parameters:
      collection - the name of the collection to delete
      guarantee - delivery guarantee
      Returns:
      a future that completes when the selected delivery guarantee is reached
    • fetchStatistics

      public List<io.fluxzero.common.api.search.DocumentStats> fetchStatistics(io.fluxzero.common.api.search.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 interface SearchClient
      Parameters:
      query - the query to filter documents
      fields - the fields to compute statistics for
      groupBy - field names used to group statistics
      Returns:
      a list of DocumentStats
    • fetchHistogram

      public io.fluxzero.common.api.search.SearchHistogram fetchHistogram(io.fluxzero.common.api.search.GetSearchHistogram request)
      Description copied from interface: SearchClient
      Fetches a histogram (bucketed time-series view) for documents matching the query.
      Specified by:
      fetchHistogram in interface SearchClient
      Parameters:
      request - the histogram query parameters
      Returns:
      a SearchHistogram representing the result
    • fetchFacetStats

      public List<io.fluxzero.common.api.search.FacetStats> fetchFacetStats(io.fluxzero.common.api.search.SearchQuery query)
      Description copied from interface: SearchClient
      Retrieves facet statistics (i.e., value counts) for a given query.
      Specified by:
      fetchFacetStats in interface SearchClient
      Parameters:
      query - the query to match documents against
      Returns:
      a list of facet statistics
    • bulkUpdate

      public CompletableFuture<Void> bulkUpdate(Collection<io.fluxzero.common.api.search.DocumentUpdate> updates, io.fluxzero.common.Guarantee guarantee)
      Description copied from interface: SearchClient
      Performs a batch update on a set of documents.
      Specified by:
      bulkUpdate in interface SearchClient
      Parameters:
      updates - the update operations to perform
      guarantee - delivery guarantee
      Returns:
      a future that completes when the selected delivery guarantee is reached
    • materializeModelCommit

      public void materializeModelCommit(io.fluxzero.common.api.modeling.CommitModels commit, List<io.fluxzero.common.api.modeling.ModelUpdate> assignedUpdates, Set<String> excludedModelIds)
      Prepares and executes document materialization for the assigned Model commit, excluding the supplied Model identifiers.
    • prepareModelCommit

      public Runnable prepareModelCommit(io.fluxzero.common.api.modeling.CommitModels commit, List<io.fluxzero.common.api.modeling.ModelUpdate> assignedUpdates, Set<String> excludedModelIds)
      Materializes direct Model documents and returns their deferred local-monitor publication.
      Returns:
      publication to invoke after the owning commit fence has advanced
    • eraseModels

      public void eraseModels(Set<String> modelIds)
      Removes storage owned by hard-erased Models, retaining independently indexed read models with coincidental IDs. The fence also rejects delayed direct materialization and deferred document publications.
    • materializeModelGraphProjection

      public void materializeModelGraphProjection(io.fluxzero.common.api.modeling.ModelGraphProjectionConfiguration configuration, Set<String> rootIds, long stateIndex, boolean rebuild)
      Synchronously materializes affected roots for the SDK-only graph-projection worker.
    • prepareModelGraphProjection

      public Runnable prepareModelGraphProjection(io.fluxzero.common.api.modeling.ModelGraphProjectionConfiguration configuration, Set<String> rootIds, long stateIndex, boolean rebuild)
      Materializes graph documents and returns their deferred local-monitor publication.
      Returns:
      publication to invoke after the graph-projection fence has advanced
    • prepareModelGraphSchemaProjection

      public Runnable prepareModelGraphSchemaProjection(io.fluxzero.common.api.modeling.ModelGraphProjectionConfiguration configuration, Set<String> rootIds, long stateIndex)
      Re-materializes only affected roots at the same business boundary after a source schema rewrite.
    • openStream

      public Stream<io.fluxzero.common.api.SerializedMessage> openStream(String collection, Long lastIndex, int maxSize)
      Returns up to maxSize document messages after lastIndex, excluding tombstones; a null index starts from the beginning and an unknown collection yields an empty stream.
    • openStream

      public Stream<io.fluxzero.common.api.SerializedMessage> openStream(String collection, Long lastIndex, int maxSize, boolean includeDocumentTombstones)
      Returns up to maxSize document messages after lastIndex, optionally including tombstones. A null index starts from the beginning; an unknown collection yields an empty stream.
    • truncateCollection

      public void truncateCollection(String collection)
      Removes the collection's documents, indices, message log, and audit trail, then notifies its monitors with an empty batch.
    • storeMessages

      protected void storeMessages(Map<String, io.fluxzero.common.api.search.SerializedDocument> updates)
    • asSerializedMessage

      protected io.fluxzero.common.api.SerializedMessage asSerializedMessage(io.fluxzero.common.api.search.SerializedDocument document)
    • purgeExpiredMessages

      protected void purgeExpiredMessages(Duration messageExpiration)
    • notifyMonitors

      protected void notifyMonitors(String collection, List<io.fluxzero.common.api.SerializedMessage> messages)
    • registerMonitor

      public io.fluxzero.common.Registration registerMonitor(BiConsumer<String, List<io.fluxzero.common.api.SerializedMessage>> monitor)
      Registers a monitor for updates across collections and returns a registration that removes it.
    • registerMonitor

      public io.fluxzero.common.Registration registerMonitor(String collection, Consumer<List<io.fluxzero.common.api.SerializedMessage>> monitor)
      Registers a monitor restricted to the supplied collection and returns a registration that removes it.
    • close

      public void close()
      Description copied from interface: SearchClient
      Closes any underlying resources.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface SearchClient