Class Score

java.lang.Object
org.springframework.data.domain.Score
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
Similarity

public sealed class Score extends Object implements Serializable permits Similarity
Value object representing a search result score computed via a ScoringFunction.

Encapsulates the numeric score and the scoring function used to derive it. Scores are primarily used to rank search results. Depending on the used ScoringFunction higher scores can indicate either a higher distance or a higher similarity. Use the Similarity class to indicate usage of a normalized score across representing effectively the similarity.

Instances of this class are immutable and suitable for use in comparison, sorting, and range operations.

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

    • of

      public static Score of(double score)
      Creates a new Score from a plain score value using ScoringFunction.unspecified().
      Parameters:
      score - the score value without a specific ScoringFunction.
      Returns:
      the new Score.
    • of

      public static Score of(double score, ScoringFunction function)
      Creates a new Score from a score value using the given ScoringFunction.
      Parameters:
      score - the score value.
      function - the scoring function that has computed the score.
      Returns:
      the new Score.
    • between

      public static Range<Score> between(Score min, Score max)
      Creates a Range from the given minimum and maximum Score values.
      Parameters:
      min - the lower score value, must not be null.
      max - the upper score value, must not be null.
      Returns:
      a Range over Score bounds.
    • getValue

      public double getValue()
      Returns the raw numeric value of the score.
      Returns:
      the score value.
    • getFunction

      public ScoringFunction getFunction()
      Returns the ScoringFunction that was used to compute this score.
      Returns:
      the associated scoring function.
    • 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