Class SearchFacets

java.lang.Object
io.goobi.viewer.model.search.SearchFacets
All Implemented Interfaces:
Serializable

public class SearchFacets extends Object implements Serializable
Current faceting settings for a search.
See Also:
  • Constructor Details

    • SearchFacets

      public SearchFacets()
  • Method Details

    • resetAvailableFacets

      public void resetAvailableFacets()
      resetAvailableFacets.
    • resetActiveFacets

      public void resetActiveFacets()
      resetCurrentFacets.
    • resetSliderRange

      public void resetSliderRange()
      resetSliderRange.
    • generateFacetFilterQueries

      public List<String> generateFacetFilterQueries(boolean includeRangeFacets)
      Generates a list containing filter queries for the selected regular and hierarchical facets.
      Parameters:
      includeRangeFacets - if true, range facet fields are included in the output
      Returns:
      a list of Solr filter query strings for the currently active facets
    • getActiveFacetsForField

      public List<IFacetItem> getActiveFacetsForField(String field)
      Returns a list of FacetItem objects in activeFacets where the field name matches the given field name.
      Parameters:
      field - Solr facet field name to match against active facets
      Returns:
      a list of active facet items that belong to the given Solr field
    • isFacetStringCurrentlyUsed

      public boolean isFacetStringCurrentlyUsed(String link)
      Parameters:
      link - facet query link string to look up in the active facets
      Returns:
      true if given link is part of the active facet string; false otherwise
    • isFacetCurrentlyUsed

      public boolean isFacetCurrentlyUsed(IFacetItem facet)
      Checks whether the given facet is currently in use.
      Parameters:
      facet - facet item to check for active use
      Returns:
      true if the given facet item is currently active (i.e. selected by the user), false otherwise
    • isFacetListSizeSufficient

      public boolean isFacetListSizeSufficient(String field)
      isFacetListSizeSufficient.
      Parameters:
      field - Solr facet field name to check
      Returns:
      true if the facet list for the given field has enough elements to be shown (more than one, or more than zero for DOCSTRCT_SUB), false otherwise
    • getAvailableFacetsListSizeForField

      public int getAvailableFacetsListSizeForField(String field)
      Returns the size of the full element list of the facet for the given field.
      Parameters:
      field - Solr facet field name to look up
      Returns:
      a int.
    • getActiveFacetsSizeForField

      public int getActiveFacetsSizeForField(String field)
      getActiveFacetsSizeForField.
      Parameters:
      field - Solr facet field name to count active facets for
      Returns:
      Size of activeFacets.
    • getLimitedFacetListForField

      public List<IFacetItem> getLimitedFacetListForField(String field)
      Returns a collapsed sublist of the available facet elements for the given field.
      Parameters:
      field - Solr facet field name whose items to retrieve
      Returns:
      a list of available facet items for the given field, trimmed to the configured display limit unless expanded
    • getAvailableFacetsForField

      public List<IFacetItem> getAvailableFacetsForField(String field, boolean excludeSelected)
      Parameters:
      field - Solr facet field name to look up in the available facets map
      excludeSelected - If true, selected facets will be removed from the list
      Returns:
      List
    • getFacet

      public IFacetItem getFacet(String field, String value)
      Parameters:
      field - Solr facet field name to search for
      value - facet value to match within the given field
      Returns:
      Specific facet item for the given field and value; null if none found
    • isUnselectedValuesAvailable

      public boolean isUnselectedValuesAvailable()
      Checks whether there are still selectable values across all available facet fields.
      Returns:
      true if any available facet field has at least one unselected value; false otherwise
    • isHasRangeFacets

      public boolean isHasRangeFacets() throws PresentationException, IndexUnreachableException
      Returns:
      true if any configured range facet field has a value range in the current search result; false otherwise
      Throws:
      PresentationException
      IndexUnreachableException
    • expandFacet

      public void expandFacet(String field)
      Sets the expanded flag to true for the given facet field.
      Parameters:
      field - Solr facet field name to expand
    • collapseFacet

      public void collapseFacet(String field)
      Sets the expanded flag to false for the given facet field.
      Parameters:
      field - Solr facet field name to collapse
    • isDisplayFacetExpandLink

      public boolean isDisplayFacetExpandLink(String field)
      Returns true if the "(more)" link is to be displayed for a facet box. This is the case if the facet has more elements than the initial number of displayed elements and the facet hasn't been manually expanded yet.
      Parameters:
      field - Solr facet field name to check expansion state for
      Returns:
      true if the facet is collapsed and has more elements than the configured initial display count, false otherwise
    • isDisplayFacetCollapseLink

      public boolean isDisplayFacetCollapseLink(String field)
      isDisplayFacetCollapseLink.
      Parameters:
      field - Solr facet field name to check expansion state for
      Returns:
      true if the facet for the given field is currently expanded and a collapse link should be shown, false otherwise
    • getActiveFacetString

      public String getActiveFacetString()
      Returns a URL encoded SSV string of facet fields and values from the elements in activeFacets (hyphen if empty).
      Returns:
      SSV string of facet queries or "-" if empty
    • setActiveFacetString

      public void setActiveFacetString(String activeFacetString)
      Receives an SSV string of facet fields and values (FIELD1:value1;FIELD2:value2;FIELD3:value3) and generates new Elements for currentFacets.
      Parameters:
      activeFacetString - SSV-encoded string of active facet field:value pairs
    • updateFacetItem

      public String updateFacetItem(String field, boolean hierarchical)
      Updates existing facet item for the given field with a new value. If no item for that field yet exist, a new one is added.
      Parameters:
      field - Solr facet field name whose item to update
      hierarchical - if true, the facet item is marked as hierarchical
      Returns:
      the JSF navigation outcome after updating the facet (e.g. "pretty:search6")
    • getHierarchicalFacets

      public static List<String> getHierarchicalFacets(String facetString, List<String> facetFields)
      getHierarchicalFacets.
      Parameters:
      facetString - SSV-encoded string of active facet field:value pairs
      facetFields - list of hierarchical facet field names to extract values for
      Returns:
      a list of hierarchical facet values extracted from the facet string for the given fields
    • splitHierarchicalFacet

      public static List<String> splitHierarchicalFacet(String facet)
      splitHierarchicalFacet.
      Parameters:
      facet - hierarchical facet value string to split into path segments
      Returns:
      a list of hierarchical path segment strings from the root level down to the given facet value
    • getCurrentMinRangeValue

      public String getCurrentMinRangeValue(String field) throws PresentationException, IndexUnreachableException
      getCurrentMinRangeValue.
      Parameters:
      field - Solr range facet field name to look up
      Returns:
      Current min value, if facet in use; otherwise absolute min value for that field
      Throws:
      PresentationException - if any.
      IndexUnreachableException - if any.
    • getCurrentMaxRangeValue

      public String getCurrentMaxRangeValue(String field) throws PresentationException, IndexUnreachableException
      getCurrentMaxRangeValue.
      Parameters:
      field - Solr range facet field name to look up
      Returns:
      Current max value, if facet in use; otherwise absolute max value for that field
      Throws:
      PresentationException - if any.
      IndexUnreachableException - if any.
    • getAbsoluteMinRangeValue

      public String getAbsoluteMinRangeValue(String field) throws PresentationException, IndexUnreachableException
      Returns the minimum value for the given field available in the search index.
      Parameters:
      field - Solr range facet field name to look up
      Returns:
      Smallest available value
      Throws:
      PresentationException - if any.
      IndexUnreachableException - if any.
    • getAbsoluteMaxRangeValue

      public String getAbsoluteMaxRangeValue(String field) throws PresentationException, IndexUnreachableException
      Returns the maximum value for the given field available in the search index.
      Parameters:
      field - Solr range facet field name to look up
      Returns:
      Largest available value
      Throws:
      PresentationException - if any.
      IndexUnreachableException - if any.
    • getValueRange

      public List<Integer> getValueRange(String field) throws PresentationException, IndexUnreachableException
      Returns a sorted list of all available values for the given field among available facet values.
      Parameters:
      field - Solr range facet field name to look up
      Returns:
      sorted list of all values for the given field among available facet values
      Throws:
      PresentationException - if any.
      IndexUnreachableException - if any.
    • getValueRangeAsJsonMap

      public String getValueRangeAsJsonMap(String field)
      Parameters:
      field - Solr range facet field name whose value range to serialize
      Returns:
      String
    • isRangeFacetActive

      public boolean isRangeFacetActive(String field)
      Parameters:
      field - Solr range facet field name to check for an active range constraint
      Returns:
      true if active range for field is currently smaller than the absolute range; false otherwise
    • resetActiveFacetString

      public void resetActiveFacetString()
      resetActiveFacetString.
    • getActiveFacetStringPrefix

      public String getActiveFacetStringPrefix()
      Returns a URL encoded value returned by generateFacetPrefix() for regular facets. Returns an empty string instead a hyphen if empty.
      Returns:
      the URL-encoded active facet string prefix for non-hierarchical facets
    • getActiveFacetStringPrefix

      public String getActiveFacetStringPrefix(String omitField)
      Parameters:
      omitField - Field name to not include in the string
      Returns:
      String object.
    • getActiveFacetStringPrefix

      public String getActiveFacetStringPrefix(List<String> omitFields, boolean urlEncode)
      Returns the value returned by generateFacetPrefix() for regular facets. Returns an empty string instead a hyphen if empty.
      Parameters:
      omitFields - Field names to omit from the facet string
      urlEncode - if true, the resulting string is URL-encoded
      Returns:
      URL part for currently selected facets; empty string if empty
    • removeFacetAction

      public String removeFacetAction(String facetQuery, String ret)
      removeFacetAction.
      Parameters:
      facetQuery - facet query string to remove from active facets
      ret - navigation outcome string to return after removal
      Returns:
      the navigation outcome string after removing the facet
    • isFacetExpanded

      public boolean isFacetExpanded(String field)
      Returns true if the value for the given field type in facetsExpanded has been previously set to true.
      Parameters:
      field - Solr facet field name to check
      Returns:
      true if the facet for the given field has been explicitly expanded, false otherwise
    • isFacetCollapsed

      public boolean isFacetCollapsed(String field)
      isFacetCollapsed.
      Parameters:
      field - Solr facet field name to check
      Returns:
      true if the facet for the given field is not expanded (i.e. collapsed), false otherwise
    • getAllRangeFacetFields

      public List<String> getAllRangeFacetFields()
      Returns:
      All facet field names of the type "range"
    • getRangeFacetStyle

      public String getRangeFacetStyle(String field)
      Parameters:
      field - Solr range facet field name whose visualization style to retrieve
      Returns:
      Visualization style for the given range field
    • getRangeFacetMinValue

      public int getRangeFacetMinValue(String field)
      Parameters:
      field - Solr range facet field name whose configured minimum to retrieve
      Returns:
      Configured min value for the given field
    • getRangeFacetMaxValue

      public int getRangeFacetMaxValue(String field)
      Parameters:
      field - Solr range facet field name whose configured maximum to retrieve
      Returns:
      Configured max value for the given field
    • getAllAvailableFacets

      public Map<String,List<IFacetItem>> getAllAvailableFacets()
      Returns configured facet fields of regular and hierarchical type only.
      Returns:
      a map of facet field name to facet items for all regular and hierarchical facet fields
    • hasAvailableFacets

      public boolean hasAvailableFacets()
    • getConfiguredSubelementFacetFields

      public List<String> getConfiguredSubelementFacetFields()
      getConfiguredSubelementFacetFields.
      Returns:
      Configured subelement fields names only
    • getAvailableFacets

      public Map<String,List<IFacetItem>> getAvailableFacets()
      Getter for the field availableFacets.
      Returns:
      the map of Solr field names to their available facet items
    • getActiveFacets

      public List<IFacetItem> getActiveFacets()
      Returns a snapshot copy of the currently active facet filters.

      Returns a defensive copy so that callers (e.g. JSF c:forEach templates) cannot receive a ConcurrentModificationException if a concurrent request modifies the list. Uses the same lock object as all write operations so that the copy is taken atomically with respect to any concurrent setActiveFacetString(java.lang.String) or setGeoFacetFeature(java.lang.String) call.

      Returns:
      a new, mutable ArrayList snapshot of the active facet filters; never null
    • getActiveFacetsCopy

      @Deprecated(since="26.04", forRemoval=true) public List<IFacetItem> getActiveFacetsCopy()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getActiveFacets() which now already returns a defensive copy.
      Get a shallow copy of activeFacets.
      Returns:
      a new ArrayList containing all activeFacets
    • removeActiveFacets

      public void removeActiveFacets(Collection<? extends IFacetItem> facetsToRemove)
      Removes all given facet items from activeFacets under the correct lock.
      Parameters:
      facetsToRemove - collection of facet items to remove; must not be null
    • isActiveFacetsEmpty

      public boolean isActiveFacetsEmpty()
      Returns whether activeFacets is empty without allocating a defensive copy.
      Returns:
      true if no active facets are set; false otherwise
    • getTempValue

      public String getTempValue()
      Getter for the field tempValue.
      Returns:
      the temporary value held during facet editing before it is applied
    • setTempValue

      public void setTempValue(String tempValue)
      Setter for the field tempValue.
      Parameters:
      tempValue - a temporary value held during facet editing before it is applied
    • isHasWrongLanguageCode

      public boolean isHasWrongLanguageCode(String field, String language)
      Returns true if the given field is language-specific to a different language than the given language.
      Parameters:
      field - Solr field name to test for a language code suffix
      language - BCP 47 language code to compare against the field suffix
      Returns:
      true if the field has a language code suffix that does not match the given language and no active facet is selected for it, false otherwise
    • getFacetValue

      public String getFacetValue(String field)
      getFacetValue.
      Parameters:
      field - Solr facet field name whose active value to retrieve
      Returns:
      the active facet value for the given field, or an empty string if no active facet exists for that field
    • getFacetDescription

      public String getFacetDescription(String field)
      getFacetDescription.
      Parameters:
      field - Solr facet field name whose active description to retrieve
      Returns:
      the CMS collection description for the active facet of the given field, or an empty string if not found
    • getFirstHierarchicalFacetValue

      public String getFirstHierarchicalFacetValue()
      getFirstHierarchicalFacetValue.
      Returns:
      the value of the first active hierarchical facet, or an empty string if none exist
    • getFirstHierarchicalFacetDescription

      public String getFirstHierarchicalFacetDescription(String field)
      getFirstHierarchicalFacetDescription.
      Parameters:
      field - Solr facet field name (unused; description taken from first hierarchical active facet)
      Returns:
      the CMS collection description for the first active hierarchical facet, or an empty string if none exist
    • getLabelMap

      public Map<String,String> getLabelMap()
    • getGeoFacetting

      public GeoFacetItem getGeoFacetting()
    • setGeoFacetFeature

      public void setGeoFacetFeature(String feature)
      Sets the feature of the geoFacettingfield to to given feature. A new GeoFacetItem is added to currentFacets if none exists yet
      Parameters:
      feature - GeoJSON feature string defining the geographic filter area
    • getGeoFacetFeature

      public String getGeoFacetFeature()
    • getActiveFacetsSize

      public int getActiveFacetsSize()