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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clear the result object.int
compareTo
(SearchResult<?> o) static <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.Obtain the result ID.void
setResultObject
(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()
-
-
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:
compareTo
in 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.
-