Package fr.becpg.repo.web.scripts.search
Class SearchFacetCounter
java.lang.Object
fr.becpg.repo.web.scripts.search.SearchFacetCounter
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe values found for one property, the most frequent first.static final recordOne value of a facet. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BiFunction<org.alfresco.service.namespace.QName, Serializable, String> private final intprivate final BiFunction<org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, Serializable> -
Constructor Summary
ConstructorsConstructorDescriptionSearchFacetCounter(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. -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidaddCountable(List<Serializable> values, Object value) 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.private List<SearchFacetCounter.FacetValue> countField(List<org.alfresco.service.cmr.repository.NodeRef> nodes, org.alfresco.service.namespace.QName field) private StringlabelOf(org.alfresco.service.namespace.QName field, Serializable value) private List<SearchFacetCounter.FacetValue> toFacetValues(org.alfresco.service.namespace.QName field, Map<String, Integer> counts, Map<String, Serializable> rawValues) 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.
-
Field Details
-
valueReader
private final BiFunction<org.alfresco.service.cmr.repository.NodeRef,org.alfresco.service.namespace.QName, valueReaderSerializable> -
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 nodelabelResolver- gives the label of a value of a propertymaxValues- 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 searchfields- 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
-
valuesOf
Flattens a property value into the values to count: each element of a multiple value, none for an empty value or a date. -
addCountable
-