Class ContentSearchHelper

java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.cms.search.content.ContentSearchHelper
All Implemented Interfaces:
LogEnabled, Component, Contextualizable, Serviceable

Component which helps content searching by providing a simple way to access content properties (either metadata or system properties).
  • Field Details

  • Constructor Details

  • Method Details

    • contextualize

      public void contextualize(Context context) throws ContextException
      Specified by:
      contextualize in interface Contextualizable
      Throws:
      ContextException
    • service

      public void service(ServiceManager manager) throws ServiceException
      Specified by:
      service in interface Serviceable
      Throws:
      ServiceException
    • getMetadataSearchField

      public SearchField getMetadataSearchField(String metadataPath, MetadataType metadataType, boolean isTypeContentWithMultilingualTitle)
      Get a SearchField 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 a SearchField corresponding to a metadata.
      Parameters:
      joinPaths - The join paths
      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.
    • getSearchField

      public Optional<SearchField> getSearchField(Collection<String> contentTypes, String fieldPath)
      Get a SearchField 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 an empty optional if not found
    • isTitleMultilingual

      public boolean isTitleMultilingual(ModelItem modelItem)
      Determines if the given model item represents an attribute of type content with contents with multilingual titles
      Parameters:
      modelItem - The model item
      Returns:
      true if the given model item represents an attribute of type content with contents with multilingual titles
    • computeJoinPaths

      public List<String> computeJoinPaths(String dataPath, Set<String> contentTypeIds, boolean addLast) throws UndefinedItemPathException
      Retrieves the join paths from the given data path
      Parameters:
      dataPath - the data path
      contentTypeIds - the ids of the content types containing the items of the given path
      addLast - true to add the last join path element to the list, false otherwise.
      Returns:
      the join paths
      Throws:
      UndefinedItemPathException - if there is no item defined at the given path in given item accessors
    • _computeJoinPaths

      protected List<String> _computeJoinPaths(String dataPath, String prefix, ModelItemAccessor modelItemAccessor, boolean addLast) throws UndefinedItemPathException
      Retrieves the join paths from the given data path
      Parameters:
      dataPath - the data path
      prefix - the prefix of current join path
      modelItemAccessor - the model item to access the items of the given path
      addLast - true to add the last join path element to the list, false otherwise.
      Returns:
      the join paths
      Throws:
      UndefinedItemPathException - if there is no item defined at the given path in given item accessor
    • _computeJoinPaths

      protected List<String> _computeJoinPaths(String dataPath, String prefix, Collection<? extends ModelItemAccessor> modelItemAccessors, boolean addLast) throws UndefinedItemPathException
      Retrieves the join paths from the given data path
      Parameters:
      dataPath - the data path
      prefix - the prefix of current join path
      modelItemAccessors - the model items to access the items of the given path
      addLast - true to add the last join path element to the list, false otherwise.
      Returns:
      the join paths
      Throws:
      UndefinedItemPathException - if there is no item defined at the given path in given item accessors
    • getAttributeValues

      public Map<String,Object> getAttributeValues(String contentId, Collection<String> dataPaths, Locale defaultLocale)
      Get attributes values by their paths
      Parameters:
      contentId - The id of content
      dataPaths - The paths of data to retrieve
      defaultLocale - 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 content
      dataPaths - 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

      public Object getAttributeValue(Content content, String dataPath, Locale defaultLocale)
      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 content
      dataPath - 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 content
      dataPath - 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.