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
Fields Modifier and Type Field Description protected ContentHelper_contentHelperThe content helper.protected ContentTypesHelper_contentTypesHelperContent Types helperprivate Context_contextprotected ContentTypeExtensionPoint_cTypeEPThe content type extension point.protected ContentTypesHelper_cTypeHelperThe content type helper.protected ServiceManager_managerAvalon service managerprotected AmetysObjectResolver_resolverThe ametys object resolver.protected SystemPropertyExtensionPoint_sysPropEPThe system property extension point.protected UserHelper_userHelperThe user helperstatic StringROLEThe component role.
-
Constructor Summary
Constructors Constructor Description ContentSearchHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private Map<String,Object>_getCompositeValues(Content content, ModelAwareComposite composite, String prefix, Locale locale, boolean full)private Map<String,Object>_getDataHolderValues(Content content, ModelAwareDataHolder dataHolder, String dataName, String dataAbsolutePathFromFirstRepeater, Locale locale, boolean full)private Map<String,Object>_getFileTransformedInfo(File file)private Map<String,Object>_getRepeaterValues(Content content, RepeaterDefinition repeaterDefinition, Object repeater, Locale locale, boolean full)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.private SearchField_getSearchField(MetadataDefinition def, List<String> joinPaths)private Map<String,Object>_getSingleRepeaterValues(Content content, RepeaterDefinition repeaterDefinition, ModelAwareRepeater repeater, Locale locale, boolean full)private Object_transformSingleValue(Content content, ElementDefinition definition, Object value, Locale locale, boolean resolveReferences)private String_transformValue(LocalDate date)private String_transformValue(ZonedDateTime dateTime)private Map<String,Object>_transformValue(Binary binary, String attributePath, String contentId)private Object_transformValue(ContentValue contentValue, Locale locale, boolean resolveReferences)private Object_transformValue(ExplorerFile file, boolean resolveReferences)private Map<String,Object>_transformValue(RichText richText)private Object_transformValue(Content content, ElementDefinition definition, Object value, Locale locale, boolean resolveReferences)Transform the raw value into a JSONified value, understandable for search UIprivate Object_transformValue(UserIdentity user)private Object_transformValue(MultilingualString multilingualString, ElementType<MultilingualString> type, Locale locale, boolean resolveReferences)voidcontextualize(Context context)ObjectgetAttributeValue(Content content, String dataPath, Locale defaultLocale)Get the value(s) of a metadata - transformed into JSONified value - of a content at given path.ObjectgetAttributeValue(Content content, String dataPath, Locale defaultLocale, boolean resolveReferences)Get the value(s) of a metadata - transformed into JSONified value - of a content at given path.ObjectgetAttributeValue(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.Map<String,Object>getAttributeValues(String contentId, Collection<String> metadataPath, Locale defaultLocale)Get metadata values by their pathMap<String,Object>getAttributeValues(Content content, Collection<String> dataPaths, Locale defaultLocale)Get metadata values by their pathSearchFieldgetMetadataSearchField(String metadataPath, MetadataType metadataType, boolean isTypeContentWithMultilingualTitle)Get aSearchFieldcorresponding to a metadata.SearchFieldgetMetadataSearchField(List<String> joinPaths, String metadataPath, MetadataType metadataType, boolean isTypeContentWithMultilingualTitle)Get aSearchFieldcorresponding to a metadata.Optional<SearchField>getSearchField(Collection<String> contentTypes, String fieldPath)Get aSearchFieldfrom a field name in a batch of content types.MetadataIndexingFieldgetTitleMetadataIndexingField()Get the metadata indexing field for the "title" standard metadata.booleanisTitleMultilingual(MetadataDefinition def)Determines if the given metadata definition represents a CONTENT metadata with contents with multilingual titlesbooleanisTitleMultilingual(ModelItem modelItem)Determines if the given metadata definition represents a CONTENT metadata with contents with multilingual titlesvoidservice(ServiceManager manager)-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
_cTypeEP
protected ContentTypeExtensionPoint _cTypeEP
The content type extension point.
-
_cTypeHelper
protected ContentTypesHelper _cTypeHelper
The content type helper.
-
_contentHelper
protected ContentHelper _contentHelper
The content helper.
-
_sysPropEP
protected SystemPropertyExtensionPoint _sysPropEP
The system property extension point.
-
_resolver
protected AmetysObjectResolver _resolver
The ametys object resolver.
-
_userHelper
protected UserHelper _userHelper
The user helper
-
_contentTypesHelper
protected ContentTypesHelper _contentTypesHelper
Content Types helper
-
_manager
protected ServiceManager _manager
Avalon service manager
-
-
Constructor Detail
-
ContentSearchHelper
public ContentSearchHelper()
-
-
Method Detail
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualizein interfaceContextualizable- Throws:
ContextException
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
getTitleMetadataIndexingField
public MetadataIndexingField 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 aSearchFieldcorresponding to a metadata.- Parameters:
metadataPath- The metadata path.metadataType- The metadata type.isTypeContentWithMultilingualTitle-trueif 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 aSearchFieldcorresponding to a metadata.- Parameters:
joinPaths- The join pathsmetadataPath- The metadata path.metadataType- The metadata type.isTypeContentWithMultilingualTitle-trueif the type is Content and the linked contents have multilingual titles- Returns:
- the search field.
-
getSearchField
public Optional<SearchField> getSearchField(Collection<String> contentTypes, String fieldPath)
Get aSearchFieldfrom 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
SearchFieldcorresponding to the field path, or anempty optionalif 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-trueto add the last join path element to the list,falseotherwise.- Returns:
- The search field or null if not found
-
_getSearchField
private SearchField _getSearchField(MetadataDefinition def, List<String> joinPaths)
-
isTitleMultilingual
public boolean isTitleMultilingual(MetadataDefinition def)
Determines if the given metadata definition represents a CONTENT metadata with contents with multilingual titles- Parameters:
def- The metadata definition- Returns:
trueif the given metadata definition represents a CONTENT metadata with contents with multilingual titles
-
isTitleMultilingual
public boolean isTitleMultilingual(ModelItem modelItem)
Determines if the given metadata definition represents a CONTENT metadata with contents with multilingual titles- Parameters:
modelItem- The metadata definition- Returns:
trueif the given metadata definition represents a CONTENT metadata with contents with multilingual titles
-
getAttributeValues
public Map<String,Object> getAttributeValues(String contentId, Collection<String> metadataPath, Locale defaultLocale)
Get metadata values by their path- Parameters:
contentId- The id of contentmetadataPath- The path of metadata to retrievedefaultLocale- The default locale to resolve multilingual values if the content's language is null. Can be null.- Returns:
- The metadata values
-
getAttributeValues
public Map<String,Object> getAttributeValues(Content content, Collection<String> dataPaths, Locale defaultLocale)
Get metadata values by their path- Parameters:
content- The initial contentdataPaths- The path of metadata to retrieve, slash-separated.defaultLocale- The default locale to resolve multilingual values if the content's language is null. Can be null.- Returns:
- The metadata values
-
getAttributeValue
public Object getAttributeValue(Content content, String dataPath, Locale defaultLocale)
Get the value(s) of a metadata - transformed into JSONified value - of a content at given path. The path can represent a path of a metadata into the content or a metadata on one or more linked contents, such as 'composite/linkedContent/secondContent/composite/metadata'. The returned value is typed.- Parameters:
content- The contentdataPath- The path to the metadata, 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 a metadata - transformed into JSONified value - of a content at given path. The path can represent a path of a metadata into the content or a metadata on one or more linked contents, such as 'composite/linkedContent/secondContent/composite/metadata'.- Parameters:
content- The contentdataPath- The path to the metadata, separated by '/'defaultLocale- The default locale to resolve multilingual values if the content's language is null. Can be null.resolveReferences-truetrue to resolve references- 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-trueto 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.
-
_getRepeaterValues
private Map<String,Object> _getRepeaterValues(Content content, RepeaterDefinition repeaterDefinition, Object repeater, Locale locale, boolean full)
-
_getSingleRepeaterValues
private Map<String,Object> _getSingleRepeaterValues(Content content, RepeaterDefinition repeaterDefinition, ModelAwareRepeater repeater, Locale locale, boolean full)
-
_getCompositeValues
private Map<String,Object> _getCompositeValues(Content content, ModelAwareComposite composite, String prefix, Locale locale, boolean full)
-
_getDataHolderValues
private Map<String,Object> _getDataHolderValues(Content content, ModelAwareDataHolder dataHolder, String dataName, String dataAbsolutePathFromFirstRepeater, Locale locale, boolean full)
-
_transformValue
private Object _transformValue(Content content, ElementDefinition definition, Object value, Locale locale, boolean resolveReferences)
Transform the raw value into a JSONified value, understandable for search UI- Parameters:
content- the contentdefinition- definition of the attribute to transformvalue- The typed values to transformlocale- Locale to use for localized values if content's language is null.resolveReferences-trueto generate full representation of attribute's values- Returns:
- The transformed values
-
_transformSingleValue
private Object _transformSingleValue(Content content, ElementDefinition definition, Object value, Locale locale, boolean resolveReferences)
-
_transformValue
private Object _transformValue(ContentValue contentValue, Locale locale, boolean resolveReferences)
-
_transformValue
private Object _transformValue(ExplorerFile file, boolean resolveReferences)
-
_transformValue
private Map<String,Object> _transformValue(Binary binary, String attributePath, String contentId)
-
_getFileTransformedInfo
private Map<String,Object> _getFileTransformedInfo(File file)
-
_transformValue
private Map<String,Object> _transformValue(RichText richText)
-
_transformValue
private String _transformValue(LocalDate date)
-
_transformValue
private String _transformValue(ZonedDateTime dateTime)
-
_transformValue
private Object _transformValue(UserIdentity user)
-
_transformValue
private Object _transformValue(MultilingualString multilingualString, ElementType<MultilingualString> type, Locale locale, boolean resolveReferences)
-
-