Class SearchResult<T extends Identifiable>
- java.lang.Object
-
- ubic.gemma.core.search.SearchResult<T>
-
- All Implemented Interfaces:
Comparable<SearchResult<?>>
public class SearchResult<T extends Identifiable> extends Object implements Comparable<SearchResult<?>>
Represents an individual search result.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:
SearchSource
,SearchResultSet
-
-
Constructor Summary
Constructors Constructor Description SearchResult()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearResultObject()
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.Long
getResultId()
Obtain the result ID.void
setResultObject(T resultObject)
Set the result object.String
toString()
SearchResult<T>
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.
-
-
-
Method Detail
-
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
public int compareTo(SearchResult<?> o)
- Specified by:
compareTo
in interfaceComparable<T extends Identifiable>
-
getResultId
@Nonnull public Long 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
public void setResultObject(T resultObject)
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
public <S extends Identifiable> SearchResult<S> withResultObject(@Nullable S resultObject)
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
public SearchResult<T> withHighlights(Map<String,String> highlights)
Copy this search result with the given highlights.
-
-