Class SearchHit<T>

java.lang.Object
io.fluxcapacitor.javaclient.persisting.search.SearchHit<T>
Type Parameters:
T - The type of the deserialized document value.
All Implemented Interfaces:
Entry<T>

public class SearchHit<T> extends Object implements Entry<T>
Represents a single result returned by a Search query.

A SearchHit encapsulates a document retrieved from the search index, along with metadata such as its unique ID, collection name, and optional timestamp and end time. The actual document value is lazily supplied via a Supplier, enabling deferred deserialization or transformation.

This class implements the Entry interface and is used extensively in streaming search operations, particularly via Search.streamHits() or Search.streamHits(int).

See Also:
  • Constructor Details

    • SearchHit

      public SearchHit()
  • Method Details

    • fromDocument

      public static SearchHit<SerializedDocument> fromDocument(SerializedDocument document)
      Constructs a SearchHit instance from a raw SerializedDocument.

      This is useful when dealing with lower-level deserialization logic or constructing hits manually in test environments or in-memory stores.

      Parameters:
      document - The serialized document from which to construct the search hit.
      Returns:
      A new SearchHit instance wrapping the serialized document.
    • getValue

      public T getValue()
      Returns the actual value of the hit, deserialized or computed via the internal valueSupplier.
      Specified by:
      getValue in interface Entry<T>
      Returns:
      The document value.
    • map

      public <V> SearchHit<V> map(Function<T,V> mapper)
      Transforms the hit’s value using the provided mapper function, producing a new SearchHit with the same metadata but with a new mapped value.
      Type Parameters:
      V - The new value type.
      Parameters:
      mapper - A function to convert the current value to another type.
      Returns:
      A new SearchHit instance with the transformed value.