Class AbstractSearchResult
- java.lang.Object
-
- com.atlassian.confluence.search.v2.AbstractSearchResult
-
- All Implemented Interfaces:
BaseSearchResult,SearchResult
- Direct Known Subclasses:
LuceneSearchResult,OpenSearchSearchResult
public abstract class AbstractSearchResult extends Object implements SearchResult
Abstract base implementation of SearchResult taken from LuceneSearchResult after removing dependency from Lucene classes- Since:
- 5.9
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractSearchResult.AlternateFieldNamesHandles alternate names for fields, typically when a field has been split or moved into another field.
-
Field Summary
-
Fields inherited from interface com.atlassian.confluence.search.v2.SearchResult
HIGHLIGHT_END, HIGHLIGHT_START
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractSearchResult()AbstractSearchResult(Function<String,ConfluenceUser> userLookup)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description StringgetContent()Gets the text content of the search result.IntegergetContentVersion()Returns the version of the content if available, ornullif there's no version for this result.DategetCreationDate()StringgetCreator()Deprecated.ConfluenceUsergetCreatorUser()Gets the person who created the entity represented by the search result.protected DategetDateResult(String key)StringgetDisplayTitle()Gets the title of the search result appropriate for displaying to a user.Map<String,String>getExtraFields()If the retrieved documents contain additional fields that cannot be directly accessed by this interface then they can be retrieved via this method.StringgetField(String fieldName)Returns the contents of the field as a string.abstract Set<String>getFieldNames()Return names of all fields of a given document.abstract StringgetFieldValue(String fieldName)Return a string value of a field of a given document, if the field has multiple values then return last value, if there is no such field then return null.abstract Set<String>getFieldValues(String fieldName)Return set of string values of a field of a given document, if the field has single value then return singleton set of that value, if there is no such field then return empty set.HandlegetHandle()Retrieves the handle that can then be used by the AnyTypeDao to retrieve the database object referenced by this search result.protected IntegergetIntegerResult(String fieldName)Set<String>getLabels(com.atlassian.user.User user)Gets the labels on the current search result that are visible to the specified user.DategetLastModificationDate()Gets the last modification date of the entity represented by the search result.StringgetLastModifier()Deprecated.ConfluenceUsergetLastModifierUser()Gets the last person to modify the entity represented by the search result.StringgetLastUpdateDescription()Gets some string describing the last modification to this content.StringgetOwnerTitle()If this result represents an attachment then this field will return the title of the page or blog post the attachment is attached to.StringgetOwnerType()If this result represents an attachment then this field will return the type of the container, a page or blogpost.Set<String>getPersonalLabels()Gets all the personal labels on the current search result.StringgetResultExcerpt()Gets excerpt from the context of the search result.protected StringgetResultExcerpt(int maxLength)protected StringgetSanitisedContent()StringgetSpaceKey()StringgetSpaceName()StringgetStatus()Gets a string representation of the entity status represented by the search result.protected StringgetStringResult(String... fieldNames)Retrieves the value for the specified field name.StringgetType()Gets a string representation of the type of the entity represented by the search result.StringgetUrlPath()Gets the URL path to the search result, relative to the site's context root.protected ConfluenceUsergetUserResult(String fieldName)Attempts to resolve the contents of the given field as aConfluenceUser.booleanhasLabels()booleanisHomePage()Checks if the search result represents the homepage of a space.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.atlassian.confluence.search.v2.BaseSearchResult
getHandleId
-
Methods inherited from interface com.atlassian.confluence.search.v2.SearchResult
getDisplayTitleWithHighlights, getExplain, getResultExcerptWithHighlights
-
-
-
-
Constructor Detail
-
AbstractSearchResult
protected AbstractSearchResult()
-
AbstractSearchResult
public AbstractSearchResult(Function<String,ConfluenceUser> userLookup)
-
-
Method Detail
-
getLabels
public Set<String> getLabels(com.atlassian.user.User user)
Description copied from interface:SearchResultGets the labels on the current search result that are visible to the specified user.- Specified by:
getLabelsin interfaceSearchResult- Parameters:
user- filter labels by this user- Returns:
- the labels on the current search result that are visible to the specified user.
-
getPersonalLabels
public Set<String> getPersonalLabels()
Description copied from interface:SearchResultGets all the personal labels on the current search result.- Specified by:
getPersonalLabelsin interfaceSearchResult- Returns:
- all the personal labels on the current search result
-
getContent
public String getContent()
Description copied from interface:SearchResultGets the text content of the search result.- Specified by:
getContentin interfaceSearchResult- Returns:
- the text content of the search result
-
getSanitisedContent
protected String getSanitisedContent()
-
getResultExcerpt
protected String getResultExcerpt(int maxLength)
-
getResultExcerpt
public String getResultExcerpt()
Description copied from interface:SearchResultGets excerpt from the context of the search result. Implementation could choose how to generate the result excerpts, for example, concatenated fragments of the document content where hits are found, or simply the first few words of the document.- Specified by:
getResultExcerptin interfaceSearchResult- Returns:
- excerpt of the content of the search result
-
getType
public String getType()
Description copied from interface:SearchResultGets a string representation of the type of the entity represented by the search result. If the entity is a content object, this is the value ofContentEntityObject.getType()- Specified by:
getTypein interfaceSearchResult- Returns:
- the type of the entity represented as a string, or null if no such type can be determined
- See Also:
ContentTypeAware.getType()
-
getStatus
public String getStatus()
Description copied from interface:SearchResultGets a string representation of the entity status represented by the search result. If the entity is a content object, this is the value ofContentEntityObject.getContentStatus()- Specified by:
getStatusin interfaceSearchResult- Returns:
- the status of the entity
-
isHomePage
public boolean isHomePage()
Description copied from interface:SearchResultChecks if the search result represents the homepage of a space.- Specified by:
isHomePagein interfaceSearchResult- Returns:
- true if the result represents the homepage of a space
-
getCreationDate
public Date getCreationDate()
- Specified by:
getCreationDatein interfaceSearchResult
-
getCreator
@Deprecated public String getCreator()
Deprecated.- Specified by:
getCreatorin interfaceSearchResult
-
getCreatorUser
public ConfluenceUser getCreatorUser()
Description copied from interface:SearchResultGets the person who created the entity represented by the search result.- Specified by:
getCreatorUserin interfaceSearchResult- Returns:
- the result's creator
-
getOwnerType
public String getOwnerType()
Description copied from interface:SearchResultIf this result represents an attachment then this field will return the type of the container, a page or blogpost.- Specified by:
getOwnerTypein interfaceSearchResult- Returns:
- the owner type
-
getOwnerTitle
public String getOwnerTitle()
Description copied from interface:SearchResultIf this result represents an attachment then this field will return the title of the page or blog post the attachment is attached to.- Specified by:
getOwnerTitlein interfaceSearchResult- Returns:
- the owner title
-
getContentVersion
public Integer getContentVersion()
Description copied from interface:SearchResultReturns the version of the content if available, ornullif there's no version for this result.- Specified by:
getContentVersionin interfaceSearchResult
-
getLastModificationDate
public Date getLastModificationDate()
Description copied from interface:SearchResultGets the last modification date of the entity represented by the search result.- Specified by:
getLastModificationDatein interfaceSearchResult- Returns:
- the last modification date of the entity
-
getLastModifier
@Deprecated public String getLastModifier()
Deprecated.- Specified by:
getLastModifierin interfaceSearchResult
-
getLastModifierUser
public ConfluenceUser getLastModifierUser()
Description copied from interface:SearchResultGets the last person to modify the entity represented by the search result.- Specified by:
getLastModifierUserin interfaceSearchResult- Returns:
- the result's last modifier
-
getDisplayTitle
public String getDisplayTitle()
Description copied from interface:SearchResultGets the title of the search result appropriate for displaying to a user. All results should return something useful for this method.- Specified by:
getDisplayTitlein interfaceSearchResult- Returns:
- the title of the search result appropriate for display on a page
- See Also:
Addressable.getDisplayTitle()
-
getUrlPath
public String getUrlPath()
Description copied from interface:SearchResultGets the URL path to the search result, relative to the site's context root. All results should return something useful for this method- Specified by:
getUrlPathin interfaceSearchResult- Returns:
- the URL path to the search result
- See Also:
Addressable.getUrlPath()
-
getLastUpdateDescription
public String getLastUpdateDescription()
Description copied from interface:SearchResultGets some string describing the last modification to this content. May be null if no such string is available. For content objects, this will be the same as the "version comment"This string is user-supplied, and therefore not internationalised
- Specified by:
getLastUpdateDescriptionin interfaceSearchResult- Returns:
- a string describing the last modification to the content
- See Also:
ContentEntityObject.getVersionComment()
-
getSpaceName
public String getSpaceName()
- Specified by:
getSpaceNamein interfaceSearchResult- Returns:
- the name of the space that contains this search result.
-
getSpaceKey
public String getSpaceKey()
- Specified by:
getSpaceKeyin interfaceSearchResult- Returns:
- the key of the space that contains this search result
-
hasLabels
public boolean hasLabels()
- Specified by:
hasLabelsin interfaceSearchResult- Returns:
- true if this search result has labels, false otherwise.
-
getExtraFields
public Map<String,String> getExtraFields()
Description copied from interface:SearchResultIf the retrieved documents contain additional fields that cannot be directly accessed by this interface then they can be retrieved via this method.The field names are abstracted from the underlying search implementation and will be centrally defined. Their values are not yet documented.
- Specified by:
getExtraFieldsin interfaceSearchResult- Returns:
- Map of additional field names and their values.
-
getHandle
public Handle getHandle()
Description copied from interface:BaseSearchResultRetrieves the handle that can then be used by the AnyTypeDao to retrieve the database object referenced by this search result.Because the database and index are not updated at the same time, it is possible for a deleted entity to still be represented in the search index. Do not assume that this handle will always refer to a live object.
- Specified by:
getHandlein interfaceBaseSearchResult- Returns:
- the handle that can be used to look up the underlying database object.
- See Also:
AnyTypeDao.findByHandle(com.atlassian.bonnie.Handle)
-
getFieldNames
public abstract Set<String> getFieldNames()
Description copied from interface:BaseSearchResultReturn names of all fields of a given document.- Specified by:
getFieldNamesin interfaceBaseSearchResult- Returns:
- names of all known fields or null
-
getField
public String getField(String fieldName)
Description copied from interface:BaseSearchResultReturns the contents of the field as a string. This method will return null if there is no content for the field or the field does not exist. FieldName is case sensitive.- Specified by:
getFieldin interfaceBaseSearchResult- Returns:
- the field value or null.
-
getFieldValue
public abstract String getFieldValue(String fieldName)
Return a string value of a field of a given document, if the field has multiple values then return last value, if there is no such field then return null.- Returns:
- a string value of a field
-
getFieldValues
public abstract Set<String> getFieldValues(String fieldName)
Return set of string values of a field of a given document, if the field has single value then return singleton set of that value, if there is no such field then return empty set.- Specified by:
getFieldValuesin interfaceBaseSearchResult- Returns:
- a string value of a field
-
getStringResult
protected String getStringResult(String... fieldNames)
Retrieves the value for the specified field name. If more than one field name is provided, it will attempt to retrieve a value for each field in order, returning as soon as a non-null value is encountered.- Parameters:
fieldNames- field name(s) to retrieve a value for- Returns:
- the first non-null value associated with the ordered list of field names passed in
-
getUserResult
protected ConfluenceUser getUserResult(String fieldName)
Attempts to resolve the contents of the given field as aConfluenceUser. The method first attempts to resolve the user using the field value as aUserKey. If that fails, it tries to resolve the user using the field value as a username. If that fails, it returns null. This is necessary because the sameSearchFieldNames.LAST_MODIFIERandSearchFieldNames.CREATORfields are used both to store userkeys (post-upgrade) and usernames (pre-upgrade).- Since:
- 5.2
-
-