Package org.ametys.cms.search.content
Class ContentSearchHelper
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.cms.search.content.ContentSearchHelper
- All Implemented Interfaces:
LogEnabled
,Component
,Contextualizable
,Serviceable
public class ContentSearchHelper
extends AbstractLogEnabled
implements Component, Serviceable, Contextualizable
Component which helps content searching by providing a simple way to access
content properties (either metadata or system properties).
-
Field Summary
Modifier and TypeFieldDescriptionprotected ContentHelper
The content helper.protected ContentTypesHelper
Content Types helperprotected ContentTypeExtensionPoint
The content type extension point.protected ContentTypesHelper
The content type helper.protected ServiceManager
Avalon service managerprotected AmetysObjectResolver
The ametys object resolver.protected SystemPropertyExtensionPoint
The system property extension point.protected UserHelper
The user helperstatic final String
The component role. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected SearchField
_getSearchField
(MetadataIndexingField indexingField, String[] remainingPathSegments, List<String> joinPaths, boolean addLast) Get the search field from the indexing field and compute the join paths.void
contextualize
(Context context) getAttributeValue
(Content content, String dataPath, Locale defaultLocale) Get the value(s) of an attribute - transformed into JSONified value - of a content at given path.getAttributeValue
(Content content, String dataPath, Locale defaultLocale, boolean resolveReferences) Get the value(s) of an attribute - transformed into JSONified value - of a content at given path.getAttributeValue
(Content content, String dataPath, ModelItem modelItem, Locale defaultLocale, boolean resolveReferences) Get the value(s) of an attribute - transformed into JSONified value - of a content at given path.getAttributeValues
(String contentId, Collection<String> dataPaths, Locale defaultLocale) Get attributes values by their pathsgetAttributeValues
(Content content, Collection<String> dataPaths, Locale defaultLocale) Get attributes values by their pathsgetMetadataSearchField
(String metadataPath, MetadataType metadataType, boolean isTypeContentWithMultilingualTitle) Get aSearchField
corresponding to a metadata.getMetadataSearchField
(List<String> joinPaths, String metadataPath, MetadataType metadataType, boolean isTypeContentWithMultilingualTitle) Get aSearchField
corresponding to a metadata.getSearchField
(Collection<String> contentTypes, String fieldPath) Get aSearchField
from a field name in a batch of content types.Get the metadata indexing field for the "title" standard metadata.boolean
Determines if the given metadata definition represents a CONTENT metadata with contents with multilingual titlesboolean
isTitleMultilingual
(ModelItem modelItem) Determines if the given metadata definition represents a CONTENT metadata with contents with multilingual titlesvoid
service
(ServiceManager manager) Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Field Details
-
ROLE
The component role. -
_cTypeEP
The content type extension point. -
_cTypeHelper
The content type helper. -
_contentHelper
The content helper. -
_sysPropEP
The system property extension point. -
_resolver
The ametys object resolver. -
_userHelper
The user helper -
_contentTypesHelper
Content Types helper -
_manager
Avalon service manager
-
-
Constructor Details
-
ContentSearchHelper
public ContentSearchHelper()
-
-
Method Details
-
contextualize
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
getTitleMetadataIndexingField
Get the metadata indexing field for the "title" standard metadata.- Returns:
- The standard title metadata indexing field.
-
getMetadataSearchField
public SearchField getMetadataSearchField(String metadataPath, MetadataType metadataType, boolean isTypeContentWithMultilingualTitle) Get aSearchField
corresponding to a metadata.- Parameters:
metadataPath
- The metadata path.metadataType
- The metadata type.isTypeContentWithMultilingualTitle
-true
if the type is Content and the linked contents have multilingual titles- Returns:
- the search field.
-
getMetadataSearchField
public SearchField getMetadataSearchField(List<String> joinPaths, String metadataPath, MetadataType metadataType, boolean isTypeContentWithMultilingualTitle) Get aSearchField
corresponding to a metadata.- Parameters:
joinPaths
- The join pathsmetadataPath
- The metadata path.metadataType
- The metadata type.isTypeContentWithMultilingualTitle
-true
if the type is Content and the linked contents have multilingual titles- Returns:
- the search field.
-
getSearchField
Get aSearchField
from a field name in a batch of content types.- Parameters:
contentTypes
- The content types, can be empty to search on any content type. In that case, only the title metadata and system properties will be usable in sort and facets specs.fieldPath
- The field path, can be either a system property ID or a indexing field name or path.- Returns:
- The
SearchField
corresponding to the field path, or anempty optional
if not found
-
_getSearchField
protected SearchField _getSearchField(MetadataIndexingField indexingField, String[] remainingPathSegments, List<String> joinPaths, boolean addLast) Get the search field from the indexing field and compute the join paths. Can be null if the last indexing field is a custom indexing field.- Parameters:
indexingField
- The initial indexing fieldremainingPathSegments
- The path to access the metadata or an another indexing field from the initial indexing fieldjoinPaths
- The consecutive's path in case of joint to access the field/metadataaddLast
-true
to add the last join path element to the list,false
otherwise.- Returns:
- The search field or null if not found
-
isTitleMultilingual
Determines if the given metadata definition represents a CONTENT metadata with contents with multilingual titles- Parameters:
def
- The metadata definition- Returns:
true
if the given metadata definition represents a CONTENT metadata with contents with multilingual titles
-
isTitleMultilingual
Determines if the given metadata definition represents a CONTENT metadata with contents with multilingual titles- Parameters:
modelItem
- The metadata definition- Returns:
true
if the given metadata definition represents a CONTENT metadata with contents with multilingual titles
-
getAttributeValues
public Map<String,Object> getAttributeValues(String contentId, Collection<String> dataPaths, Locale defaultLocale) Get attributes values by their paths- Parameters:
contentId
- The id of contentdataPaths
- The paths of data to retrievedefaultLocale
- The default locale to resolve multilingual values if the content's language is null. Can be null.- Returns:
- The attributes values
-
getAttributeValues
public Map<String,Object> getAttributeValues(Content content, Collection<String> dataPaths, Locale defaultLocale) Get attributes values by their paths- Parameters:
content
- The initial contentdataPaths
- The path of data to retrieve, slash-separated.defaultLocale
- The default locale to resolve multilingual values if the content's language is null. Can be null.- Returns:
- The attributes values
-
getAttributeValue
Get the value(s) of an attribute - transformed into JSONified value - of a content at given path. The path can represent a path of an attribute into the content or an attribute on one or more linked contents, such as 'composite/linkedContent/secondContent/composite/attribute'. The returned value is typed.- Parameters:
content
- The contentdataPath
- The path to the attribute, separated by '/'defaultLocale
- The default locale to resolve multilingual values if the content's language is null. Can be null.- Returns:
- The final value.
-
getAttributeValue
public Object getAttributeValue(Content content, String dataPath, Locale defaultLocale, boolean resolveReferences) Get the value(s) of an attribute - transformed into JSONified value - of a content at given path. The path can represent a path of an attribute into the content or an attribute on one or more linked contents, such as 'composite/linkedContent/secondContent/composite/attribute'.- Parameters:
content
- The contentdataPath
- The path to the attribute, separated by '/'defaultLocale
- The default locale to resolve multilingual values if the content's language is null. Can be null.resolveReferences
-true
to generate full representation of attribute's values : the references will be resolved and the label of enumerated values will be returned.- Returns:
- The final value, transformed for search.
-
getAttributeValue
public Object getAttributeValue(Content content, String dataPath, ModelItem modelItem, Locale defaultLocale, boolean resolveReferences) Get the value(s) of an attribute - transformed into JSONified value - of a content at given path. The path can represent a path of an attribute into the content or an attribute on one or more linked contents, such as 'composite/linkedContent/secondContent/composite/attribute'.- Parameters:
content
- The initial content.dataPath
- The path to the attribute, separated by '/'modelItem
- The attribute definition.defaultLocale
- The default locale to resolve multilingual values if the content's language is null. Can be null.resolveReferences
-true
to generate full representation of attribute's values : the references will be resolved and the label of enumerated values will be returned.- Returns:
- The final value, transformed for search.
-