Class SearchResult<T>

java.lang.Object
org.springframework.data.domain.SearchResult<T>
Type Parameters:
T - the type of the content object
All Implemented Interfaces:
Serializable

public final class SearchResult<T> extends Object implements Serializable
Immutable value object representing a search result consisting of a content item and an associated Score.

Typically used in the context of similarity-based or vector search operations where each result carries a relevance Score. Provides accessor methods for the content and its score, along with transformation support via map(Function).

Since:
4.0
Author:
Mark Paluch
See Also:
  • Constructor Details

    • SearchResult

      public SearchResult(T content, Score score)
      Creates a new SearchResult with the given content and Score.
      Parameters:
      content - the result content, must not be null.
      score - the result score, must not be null.
    • SearchResult

      public SearchResult(T content, double score)
      Create a new SearchResult with the given content and a raw score value.
      Parameters:
      content - the result content, must not be null.
      score - the score value.
  • Method Details

    • getContent

      public T getContent()
      Returns the content associated with this result.
    • getScore

      public Score getScore()
      Returns the Score associated with this result.
    • map

      public <U> SearchResult<U> map(Function<? super T,? extends U> converter)
      Creates a new SearchResult by applying the given mapping Function to this result's content.
      Type Parameters:
      U - the target type of the mapped content.
      Parameters:
      converter - the mapping function to apply to the content, must not be null.
      Returns:
      a new SearchResult instance with converted content.
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object