Class FixedIntervalFacetCreator

java.lang.Object
de.cxp.ocs.elasticsearch.facets.FixedIntervalFacetCreator
All Implemented Interfaces:
CustomFacetCreator

public abstract class FixedIntervalFacetCreator extends Object implements CustomFacetCreator
The basis for a interval facet creator that should extract facets with fixed intervals.

Why is it not possible to have a configurable FixedIntervalFacetCreator? Because a single facet creator will be used for all facets it is configured for. So it is not possible to configure one FixedIntervalFacetCreator for different facets with different interval ranges.

That's why one would need to create for example a "RatingFacetCreator" and a "FixedPriceIntervalFacetCreator" with different ranges and different "custom facet types" to meet its requirements.

Unless "configurable single-use facet creators" are not supported, this is the (only?) way to support that kind of requirement with minimal effort.

Author:
rb@commerce-experts.com
  • Constructor Details

  • Method Details

    • getAcceptibleFieldType

      public FieldType getAcceptibleFieldType()
      Description copied from interface: CustomFacetCreator
      Specify for which field type this creator works. Must be one of: STRING, NUMBER, CATEGORY. A facet creator can not work for different field types - in that case different implementation of the facet-creator with different
      Specified by:
      getAcceptibleFieldType in interface CustomFacetCreator
      Returns:
    • getUniqAggregationName

      protected String getUniqAggregationName()
    • buildAggregation

      public org.elasticsearch.search.aggregations.AggregationBuilder buildAggregation(String fullFieldName)
      Description copied from interface: CustomFacetCreator
      Build the (sub)-aggregation that should be applied on the values of each field with that facet-type. The same aggregation is used for all facets of that type.
      Specified by:
      buildAggregation in interface CustomFacetCreator
      Parameters:
      fullFieldName - the 'full value field name' to be used as aggregation field-name.
      Returns:
    • createFacet

      public Optional<Facet> createFacet(org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket facetNameBucket, FacetConfiguration.FacetConfig facetConfig, InternalResultFilter facetFilter, LinkBuilder linkBuilder, Function<org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket,Long> nestedValueBucketDocCountCorrector)
      Description copied from interface: CustomFacetCreator
      Create a facet from the given aggregation result.
      Specified by:
      createFacet in interface CustomFacetCreator
      Parameters:
      facetNameBucket - The terms bucket of that facet field. The key of that bucket is the field name. It contains the required aggregation results as sub-aggregation.
      facetConfig - the config of the facet to be created
      facetFilter - a nullable filter if there is a filter applied for facet. Necessary to set the according values as selected.
      linkBuilder - a helper to create links for facet values / filters.
      Returns:
      facet if it can be created otherwise an empty optional.
    • fillFacet

      protected <T extends Number> void fillFacet(org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket facetNameBucket, Facet facet, FacetConfiguration.FacetConfig facetConfig, LinkBuilder linkBuilder, NumberResultFilter selectedFilter, Function<org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket,Long> nestedValueBucketDocCountCorrector)
    • createIntervalFacetEntry

      protected FacetEntry createIntervalFacetEntry(NumericFacetEntryBuilder currentValueInterval, NumberResultFilter selectedFilter, FacetConfiguration.FacetConfig facetConfig, LinkBuilder linkBuilder)
    • mergeFacets

      public Optional<Facet> mergeFacets(Facet first, Facet second)
      Description copied from interface: CustomFacetCreator
      In case such a custom facet should be created on a field that is indexed on variant and master level, two facets are created and should be merged. If that is not possible feel free to log an error and return Optional.empty or just one of those facets.
      Specified by:
      mergeFacets in interface CustomFacetCreator
      Parameters:
      first -
      second -
      Returns: