Class RelatedContentHelper

java.lang.Object
org.codelibs.fess.helper.AbstractConfigHelper
org.codelibs.fess.helper.RelatedContentHelper

public class RelatedContentHelper extends AbstractConfigHelper
Helper class for managing related content configurations. This class provides functionality to load, cache, and retrieve related content based on search queries and virtual host configurations. It supports both exact term matching and regex pattern matching for flexible content association.
  • Field Details

    • relatedContentMap

      protected Map<String,org.codelibs.core.misc.Pair<Map<String,String>,List<org.codelibs.core.misc.Pair<Pattern,String>>>> relatedContentMap
      Cache map storing related content configurations organized by virtual host key. The outer map key is the virtual host key, and the value is a pair containing: - First: Map of exact term matches (term -> content) - Second: List of regex pattern matches (Pattern -> content template)
    • regexPrefix

      protected String regexPrefix
      Prefix used to identify regex patterns in related content terms. When a term starts with this prefix, it is treated as a regular expression pattern rather than an exact match term.
    • queryPlaceHolder

      protected String queryPlaceHolder
      Placeholder string used in regex-based related content templates. This placeholder is replaced with the actual search query when a regex pattern matches the query.
  • Constructor Details

    • RelatedContentHelper

      public RelatedContentHelper()
      Default constructor for RelatedContentHelper. The constructor does not perform any initialization logic as the actual initialization is handled by the init() method annotated with @PostConstruct.
  • Method Details

    • init

      @PostConstruct public void init()
      Initializes the RelatedContentHelper by loading related content configurations from the data store. This method is called automatically after dependency injection is complete. PostConstruct annotation ensures this method is called after the bean has been constructed and all dependencies have been injected.
    • getAvailableRelatedContentList

      public List<org.codelibs.fess.opensearch.config.exentity.RelatedContent> getAvailableRelatedContentList()
      Retrieves all available related content configurations from the data store. The results are ordered by sort order ascending, then by term ascending. The number of results is limited by the configured maximum fetch size.
      Returns:
      List of RelatedContent entities containing all available related content configurations
    • load

      public int load()
      Description copied from class: AbstractConfigHelper
      Load the configuration.
      Specified by:
      load in class AbstractConfigHelper
      Returns:
      The number of loaded configurations.
    • getHostKey

      protected String getHostKey(org.codelibs.fess.opensearch.config.exentity.RelatedContent entity)
      Extracts the virtual host key from a RelatedContent entity. If the virtual host is blank or null, returns an empty string. This key is used to organize related content by virtual host.
      Parameters:
      entity - the RelatedContent entity to extract the host key from
      Returns:
      the virtual host key, or empty string if not specified
    • getRelatedContents

      public String[] getRelatedContents(String query)
      Retrieves related content for a given search query. First checks for exact term matches, then evaluates regex patterns. For regex matches, the query placeholder is replaced with the actual query.
      Parameters:
      query - the search query to find related content for
      Returns:
      array of related content strings, or empty array if no matches found
    • setRegexPrefix

      public void setRegexPrefix(String regexPrefix)
      Sets the prefix used to identify regex patterns in related content terms. When a term starts with this prefix, it is treated as a regular expression pattern rather than an exact match term.
      Parameters:
      regexPrefix - the prefix string to identify regex patterns (default: "regex:")
    • setQueryPlaceHolder

      public void setQueryPlaceHolder(String queryPlaceHolder)
      Sets the placeholder string used in regex-based related content templates. This placeholder is replaced with the actual search query when a regex pattern matches the query.
      Parameters:
      queryPlaceHolder - the placeholder string to be replaced with the query (default: "__QUERY__")