Class SearchResult<T extends Identifiable>
- All Implemented Interfaces:
Comparable<SearchResult<?>>
Search result minimally have a type and ID and may have their result object populated at a later time via setResultObject(Identifiable).
Results have a score and possibly number of highlights. Two results are considered equal if they have the same type
and ID. You may use a SearchResultSet to combine results in a sensible way, retaining result objects and
highlights when a better result is added.
- Author:
- paul, poirigui
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSearchResult(Class<? extends Identifiable> resultType, long resultId, double score, Map<String, String> highlights, Object source) Creates a newSearchResultinstance. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanvoidClear the result object.intcompareTo(SearchResult<?> o) booleanstatic <T extends Identifiable>
SearchResult<T> from(Class<? extends Identifiable> resultType, long entityId, double score, Map<String, String> highlights, Object source) Create a new provisional search result with a result type and ID.static <T extends Identifiable>
SearchResult<T> from(Class<? extends Identifiable> resultType, T entity, double score, Map<String, String> highlights, Object source) Create a search result from a given identifiable entity.Highlights for this result.Obtain the result ID.Result object this search result is referring to.Class<? extends Identifiable> Type of search result, immutable.doublegetScore()Score for ranking this result among other results.Object representing the source of this result object.inthashCode()voidsetResultObject(T resultObject) Set the result object.toString()withHighlights(Map<String, String> highlights) Copy this search result with the given highlights.<S extends Identifiable>
SearchResult<S> withResultObject(S resultObject) Create a search result from an existing one, replacing the result object with the target one.
-
Constructor Details
-
SearchResult
public SearchResult(Class<? extends Identifiable> resultType, long resultId, double score, @Nullable Map<String, String> highlights, Object source) Creates a newSearchResultinstance.- Parameters:
resultType- Type of search result, immutable.resultId- ID of the result, immutable.score- Score for ranking this result among other results.highlights- Highlights for this result.Keys are fields of
SearchResultand values are substrings that were matched.source- Object representing the source of this result object.This can simply be a
String.
-
-
Method Details
-
from
public static <T extends Identifiable> SearchResult<T> from(Class<? extends Identifiable> resultType, T entity, double score, @Nullable Map<String, String> highlights, Object source) Create a search result from a given identifiable entity.The result can be cleared later with
clearResultObject(). -
from
public static <T extends Identifiable> SearchResult<T> from(Class<? extends Identifiable> resultType, long entityId, double score, @Nullable Map<String, String> highlights, Object source) Create a new provisional search result with a result type and ID.The result can be set later with
setResultObject(Identifiable). -
compareTo
- Specified by:
compareToin interfaceComparable<T extends Identifiable>
-
toString
-
getResultId
Obtain the result ID.For consistency with
Identifiable.getId(), thus returns aLong. It is however backed internally by a native long and cannot ever be null. -
setResultObject
Set the result object.- Throws:
IllegalArgumentException- if the provided result object is null or if its ID differs fromgetResultId().
-
clearResultObject
public void clearResultObject()Clear the result object. -
withResultObject
Create a search result from an existing one, replacing the result object with the target one.The new result object does not have to be of the same type as the original result object. This is useful if you need to convert the result object (i.e. to a VO) while preserving the metadata (score, highlighted text, etc.).
-
withHighlights
Copy this search result with the given highlights. -
getResultType
Type of search result, immutable. -
getResultObject
Result object this search result is referring to.This can be null, at least initially if the resultType and resultId are provided.
It may also be replaced at a later time via
setResultObject(Identifiable). -
getScore
public double getScore()Score for ranking this result among other results. -
getHighlights
Highlights for this result.Keys are fields of
SearchResultand values are substrings that were matched. -
getSource
Object representing the source of this result object.This can simply be a
String. -
equals
-
canEqual
-
hashCode
public int hashCode()
-