Class SearchFacetUtils<F extends com.broadleafcommerce.search.api.domain.Facet>

java.lang.Object
com.broadleafcommerce.search.core.service.facet.SearchFacetUtils<F>

public class SearchFacetUtils<F extends com.broadleafcommerce.search.api.domain.Facet> extends Object
Utilities for working with Facets.
Since:
2.1.0-GA
Author:
Nathan Moore (nathandmoore)
  • Constructor Details

    • SearchFacetUtils

      public SearchFacetUtils(SettingsFacetGroupService<com.broadleafcommerce.search.api.domain.SettingsFacetGroup> settingsFacetGroupService, FacetGroupService<com.broadleafcommerce.search.api.domain.FacetGroup> facetGroupService, FacetGroupFacetService<com.broadleafcommerce.search.api.domain.FacetGroupFacet> facetGroupFacetService, FacetService<F> facetService, com.broadleafcommerce.search.autoconfigure.SearchSettingsProperties searchSettingsProperties, SearchSettingsUtils searchSettingsUtils)
  • Method Details

    • hydrateFacetsOntoFields

      public void hydrateFacetsOntoFields(@NonNull @NonNull com.broadleafcommerce.search.api.domain.SearchRequest searchRequest, @NonNull @NonNull List<? extends com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Hydrates Facets onto the provided FieldDefinitions for the given SearchRequest. If SearchSettings are enabled, then this will look up the SearchSettings first to find the appropriate settings for the application or tenant in context. Then it will clear all facet related fields on the field definitions and re-hydrate them based on the facets configured. Otherwise, it will simply pass the field definitions through as they already have the appropriate information.

      This will use a copy of the given ContextInfo that has ContextInfo.isIgnoreCatalogNarrowing() set to true when reading search settings and related domain since the Catalog ID on the request will be for the indexable type being queried on not the Search Group the settings belong to.

      Parameters:
      searchRequest - Incoming request
      fieldDefinitions - List of resolved FieldDefinitions appropriate for the indexable type.
      originalContext - Additional sandbox and multitenant info.
    • determineFacetsForSearchRequest

      protected List<F> determineFacetsForSearchRequest(@NonNull @NonNull List<? extends com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions, String indexableType, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    • determineAvailableFacetsForFacetGroup

      protected List<F> determineAvailableFacetsForFacetGroup(com.broadleafcommerce.search.api.domain.SettingsFacetGroup settingsFacetGroup, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Determines the list of available facets for the given SettingsFacetGroup. The facets will be ordered first by the Sort value of their FacetGroupFacet, and then by the Facet.getDisplayOrder(), if the Sort value is not set.
      Parameters:
      settingsFacetGroup - the SettingsFacetGroup to determine facets for
      contextInfo - The context information surrounding sandboxing/multitenant state
      Returns:
      the list of available facets for the given SettingsFacetGroup
    • determineSettingsFacetGroup

      protected Optional<com.broadleafcommerce.search.api.domain.SettingsFacetGroup> determineSettingsFacetGroup(com.broadleafcommerce.search.api.domain.SearchSettings searchSettings, String indexableType, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • readFacetsById

      protected List<F> readFacetsById(@NonNull @NonNull List<com.broadleafcommerce.search.api.domain.FacetGroupFacet> facetGroupFacets, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • attachFacetsToFacetGroupFacets

      protected void attachFacetsToFacetGroupFacets(@NonNull @NonNull List<com.broadleafcommerce.search.api.domain.FacetGroupFacet> facetGroupFacets, @NonNull @NonNull Map<String,F> facetMapById)
    • buildOrderFacetsStream

      protected Stream<String> buildOrderFacetsStream(@NonNull @NonNull List<com.broadleafcommerce.search.api.domain.FacetGroupFacet> facetGroupFacets, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • gatherFacetIdsBySort

      protected Stream<String> gatherFacetIdsBySort(@NonNull @NonNull List<com.broadleafcommerce.search.api.domain.FacetGroupFacet> facetGroupFacets, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • gatherFacetIdsByDisplayOrder

      protected Stream<String> gatherFacetIdsByDisplayOrder(@NonNull @NonNull List<com.broadleafcommerce.search.api.domain.FacetGroupFacet> facetGroupFacets, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • determineOrderedFacets

      protected List<F> determineOrderedFacets(@NonNull @NonNull Stream<String> orderedFacetIds, @NonNull @NonNull Map<String,F> facetMapById, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • getSettingsFacetGroupService

      protected SettingsFacetGroupService<com.broadleafcommerce.search.api.domain.SettingsFacetGroup> getSettingsFacetGroupService()
    • getFacetGroupService

      protected FacetGroupService<com.broadleafcommerce.search.api.domain.FacetGroup> getFacetGroupService()
    • getFacetGroupFacetService

      protected FacetGroupFacetService<com.broadleafcommerce.search.api.domain.FacetGroupFacet> getFacetGroupFacetService()
    • getFacetService

      protected FacetService<F> getFacetService()
    • getSearchSettingsProperties

      protected com.broadleafcommerce.search.autoconfigure.SearchSettingsProperties getSearchSettingsProperties()
    • getSearchSettingsUtils

      protected SearchSettingsUtils getSearchSettingsUtils()