Class SearchFacetCounter

java.lang.Object
fr.becpg.repo.web.scripts.search.SearchFacetCounter

public final class SearchFacetCounter extends Object
Counts, over the nodes a search found, how many carry each value of a few properties. The counts are made on the result list itself rather than asked to the index, so they hold whatever served the search (database, index, or a filter applied afterwards). Dates are left out: one value per day makes no useful filter.
Author:
matthieu
  • Field Details

    • valueReader

      private final BiFunction<org.alfresco.service.cmr.repository.NodeRef,org.alfresco.service.namespace.QName,Serializable> valueReader
    • labelResolver

      private final BiFunction<org.alfresco.service.namespace.QName,Serializable,String> labelResolver
    • maxValues

      private final int maxValues
  • Constructor Details

    • SearchFacetCounter

      public SearchFacetCounter(BiFunction<org.alfresco.service.cmr.repository.NodeRef,org.alfresco.service.namespace.QName,Serializable> valueReader, BiFunction<org.alfresco.service.namespace.QName,Serializable,String> labelResolver, int maxValues)

      Constructor for SearchFacetCounter.

      Parameters:
      valueReader - reads the value of a property on a node
      labelResolver - gives the label of a value of a property
      maxValues - the most values kept per facet
  • Method Details

    • count

      public List<SearchFacetCounter.Facet> count(List<org.alfresco.service.cmr.repository.NodeRef> nodes, List<org.alfresco.service.namespace.QName> fields)
      Counts the values of the given properties over the nodes.
      Parameters:
      nodes - the nodes found by the search
      fields - the properties to count
      Returns:
      one facet per property having at least one value
    • countField

      private List<SearchFacetCounter.FacetValue> countField(List<org.alfresco.service.cmr.repository.NodeRef> nodes, org.alfresco.service.namespace.QName field)
    • toFacetValues

      private List<SearchFacetCounter.FacetValue> toFacetValues(org.alfresco.service.namespace.QName field, Map<String,Integer> counts, Map<String,Serializable> rawValues)
    • labelOf

      private String labelOf(org.alfresco.service.namespace.QName field, Serializable value)
    • valuesOf

      private static List<Serializable> valuesOf(Serializable value)
      Flattens a property value into the values to count: each element of a multiple value, none for an empty value or a date.
    • addCountable

      private static void addCountable(List<Serializable> values, Object value)