Class SearchResults<T>

java.lang.Object
org.springframework.data.domain.SearchResults<T>
Type Parameters:
T - the type of content contained within each SearchResult.
All Implemented Interfaces:
Serializable, Iterable<SearchResult<T>>

public class SearchResults<T> extends Object implements Iterable<SearchResult<T>>, Serializable
Value object encapsulating a collection of SearchResult instances.

Typically used as the result type for search or similarity queries, exposing access to the result content and supporting mapping operations to transform the result content type.

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

    • SearchResults

      public SearchResults(List<? extends SearchResult<T>> results)
      Creates a new SearchResults instance from the given list of SearchResult items.
      Parameters:
      results - the search results to encapsulate, must not be null
  • Method Details

    • getContent

      public List<SearchResult<T>> getContent()
      Return the actual content of the SearchResult items as an unmodifiable list.
    • iterator

      public Iterator<SearchResult<T>> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • stream

      public Stream<SearchResult<T>> stream()
      Returns a sequential Stream containing SearchResult items in this SearchResults instance.
      Returns:
      a sequential Stream containing SearchResult items in this SearchResults instance.
    • contentStream

      public Stream<T> contentStream()
      Returns a sequential Stream containing unwrapped content items in this SearchResults instance.
      Returns:
      a sequential Stream containing unwrapped content items in this SearchResults instance.
    • map

      public <U> SearchResults<U> map(Function<? super T,? extends U> converter)
      Creates a new SearchResults instance with the content of the current results mapped via the given Function.
      Type Parameters:
      U - the target type of the mapped content.
      Parameters:
      converter - the mapping function to apply to the content of each SearchResult, must not be null.
      Returns:
      a new SearchResults instance containing mapped result content.
    • equals

      public boolean equals(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