Class TranslationSolrDocumentBuilderContributor

java.lang.Object
com.broadleafcommerce.search.index.solr.document.TranslationSolrDocumentBuilderContributor
All Implemented Interfaces:
com.broadleafcommerce.search.index.core.document.DocumentBuilderContributor<org.apache.solr.common.SolrInputDocument>

public class TranslationSolrDocumentBuilderContributor extends Object implements com.broadleafcommerce.search.index.core.document.DocumentBuilderContributor<org.apache.solr.common.SolrInputDocument>
Contribute translated field values to the SolrInputDocument in the available locales.
  • Constructor Summary

    Constructors
    Constructor
    Description
    TranslationSolrDocumentBuilderContributor(com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService, com.broadleafcommerce.search.index.core.document.helper.DocumentBuilderHelper documentBuilderHelper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.broadleafcommerce.search.index.core.service.IndexerTenantService tenantService)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected List<com.broadleafcommerce.search.api.domain.translation.Translation>
    applyDefaultSortOnLocaleTranslations(Map<String,List<com.broadleafcommerce.search.api.domain.translation.Translation>> localeBasedTranslations, String language)
    Hook point to override determination of which locale translations take precedence during reindexing of translatable fields in the absence of language-specific translations.
    protected void
    applyTranslation(com.jayway.jsonpath.DocumentContext context, com.broadleafcommerce.search.api.domain.translation.Translation translation)
    Update the JSON document with the provided translation.
    protected void
    attachLanguageBasedTranslations(com.broadleafcommerce.search.api.domain.Indexable<?> indexable, org.apache.solr.common.SolrInputDocument document, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fields, Set<String> languages)
     
    protected void
    attachLocaleBasedTranslations(com.broadleafcommerce.search.api.domain.Indexable<?> indexable, org.apache.solr.common.SolrInputDocument document, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fields, Set<String> locales)
     
    protected void
    attachTranslationsForLocale(Map<String,Object> json, org.apache.solr.common.SolrInputDocument document, String languageOrLocale, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fields)
    Populate all translatable fields in the document in the given locale, with values from the provided translated indexable JSON.
    boolean
    canHandle(com.broadleafcommerce.search.api.domain.Indexable<?> indexable)
     
    void
    contributeInternal(com.broadleafcommerce.search.api.domain.Indexable<?> indexable, org.apache.solr.common.SolrInputDocument document, com.jayway.jsonpath.DocumentContext context, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fields)
     
    protected List<com.broadleafcommerce.search.api.domain.translation.Translation>
    filterTranslationsForLanguage(List<com.broadleafcommerce.search.api.domain.translation.Translation> translations, String language)
    Retrieve only translations which apply in the provided language.
    protected List<com.broadleafcommerce.search.api.domain.translation.Translation>
    filterTranslationsForLocale(List<com.broadleafcommerce.search.api.domain.translation.Translation> translations, String locale)
    Retrieve only translations which apply in the provided locale.
    protected org.modelmapper.ModelMapper
     
    protected com.broadleafcommerce.search.index.core.document.helper.DocumentBuilderHelper
     
    protected Collection<String>
    getJsonPaths(com.broadleafcommerce.search.api.domain.translation.Translation translation)
    Get the JSONPath strings which correspond to the translation field's paths in the indexable JSON payload.
    protected Set<String>
     
    protected com.fasterxml.jackson.databind.ObjectMapper
     
    protected com.broadleafcommerce.search.provider.solr.SolrFieldService
     
    protected com.broadleafcommerce.search.index.core.service.IndexerTenantService
     
    protected com.broadleafcommerce.search.autoconfigure.SearchCommonTranslationProperties
     
    protected com.broadleafcommerce.common.extension.TypeFactory
     
    void
    setTranslationProperties(com.broadleafcommerce.search.autoconfigure.SearchCommonTranslationProperties translationProperties)
     
    protected <I> Map<String,Object>
    translateIndexableJson(com.broadleafcommerce.search.api.domain.Indexable<I> indexable, List<com.broadleafcommerce.search.api.domain.translation.Translation> languageTranslations, List<com.broadleafcommerce.search.api.domain.translation.Translation> localeTranslations)
    Translate the given indexable's JSON data with the given translations.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.broadleafcommerce.search.index.core.document.DocumentBuilderContributor

    contribute
  • Constructor Details

    • TranslationSolrDocumentBuilderContributor

      public TranslationSolrDocumentBuilderContributor(com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService, com.broadleafcommerce.search.index.core.document.helper.DocumentBuilderHelper documentBuilderHelper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.broadleafcommerce.search.index.core.service.IndexerTenantService tenantService)
  • Method Details

    • contributeInternal

      public void contributeInternal(com.broadleafcommerce.search.api.domain.Indexable<?> indexable, org.apache.solr.common.SolrInputDocument document, com.jayway.jsonpath.DocumentContext context, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fields)
      Specified by:
      contributeInternal in interface com.broadleafcommerce.search.index.core.document.DocumentBuilderContributor<org.apache.solr.common.SolrInputDocument>
    • attachLocaleBasedTranslations

      protected void attachLocaleBasedTranslations(com.broadleafcommerce.search.api.domain.Indexable<?> indexable, org.apache.solr.common.SolrInputDocument document, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fields, Set<String> locales)
    • getLanguagesForLocales

      protected Set<String> getLanguagesForLocales(Set<String> locales)
    • filterTranslationsForLocale

      protected List<com.broadleafcommerce.search.api.domain.translation.Translation> filterTranslationsForLocale(List<com.broadleafcommerce.search.api.domain.translation.Translation> translations, String locale)
      Retrieve only translations which apply in the provided locale.
      Parameters:
      translations - all translations to be filtered
      locale - locale to filter for
      Returns:
      translations which apply in this locale
    • attachLanguageBasedTranslations

      protected void attachLanguageBasedTranslations(com.broadleafcommerce.search.api.domain.Indexable<?> indexable, org.apache.solr.common.SolrInputDocument document, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fields, Set<String> languages)
    • translateIndexableJson

      protected <I> Map<String,Object> translateIndexableJson(com.broadleafcommerce.search.api.domain.Indexable<I> indexable, List<com.broadleafcommerce.search.api.domain.translation.Translation> languageTranslations, List<com.broadleafcommerce.search.api.domain.translation.Translation> localeTranslations)
      Translate the given indexable's JSON data with the given translations.
      Type Parameters:
      I - the ID type for the indexable
      Parameters:
      indexable - indexable to be translated
      languageTranslations - language translations to use for translating
      localeTranslations - locale translations to use for translating
      Returns:
      a map with the indexable's JSON data translated
    • applyTranslation

      protected void applyTranslation(com.jayway.jsonpath.DocumentContext context, com.broadleafcommerce.search.api.domain.translation.Translation translation)
      Update the JSON document with the provided translation.
      Parameters:
      context - JSON document to update
      translation - translation to apply
    • getJsonPaths

      protected Collection<String> getJsonPaths(com.broadleafcommerce.search.api.domain.translation.Translation translation)
      Get the JSONPath strings which correspond to the translation field's paths in the indexable JSON payload.

      This implementation assumes that all translations should be applied from the JSON root.

      Parameters:
      translation - translation to create JSONPath for
      Returns:
      JSONPath for the translation in the indexable JSON
    • attachTranslationsForLocale

      protected void attachTranslationsForLocale(Map<String,Object> json, org.apache.solr.common.SolrInputDocument document, String languageOrLocale, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fields)
      Populate all translatable fields in the document in the given locale, with values from the provided translated indexable JSON.
      Parameters:
      json - translated indexable JSON
      document - document to which translated fields should be attached
      languageOrLocale - the language or locale for the translated fields to be attached
      fields - all fields for the indexable type
    • filterTranslationsForLanguage

      protected List<com.broadleafcommerce.search.api.domain.translation.Translation> filterTranslationsForLanguage(List<com.broadleafcommerce.search.api.domain.translation.Translation> translations, String language)
      Retrieve only translations which apply in the provided language. If there are multiple translations, uses the most specific (language-based) translation, e.g. field_en; otherwise, uses a default sort order on the locale translations for consistent results.
      Parameters:
      translations - all translations to be filtered
      language - language to filter for
      Returns:
      translations which apply in this language
    • applyDefaultSortOnLocaleTranslations

      protected List<com.broadleafcommerce.search.api.domain.translation.Translation> applyDefaultSortOnLocaleTranslations(Map<String,List<com.broadleafcommerce.search.api.domain.translation.Translation>> localeBasedTranslations, String language)
      Hook point to override determination of which locale translations take precedence during reindexing of translatable fields in the absence of language-specific translations. Not used when country-specific indexing is enabled, see SearchCommonTranslationProperties.shouldIndexCountrySpecificLanguageDialects().
      Parameters:
      localeBasedTranslations - the list of translations mapped by the entityField
      language - the current language for the translated fields
      Returns:
      the list of locale-based translations that should apply for the language
    • canHandle

      public boolean canHandle(com.broadleafcommerce.search.api.domain.Indexable<?> indexable)
      Specified by:
      canHandle in interface com.broadleafcommerce.search.index.core.document.DocumentBuilderContributor<org.apache.solr.common.SolrInputDocument>
    • getSolrFieldService

      protected com.broadleafcommerce.search.provider.solr.SolrFieldService getSolrFieldService()
    • getDocumentBuilderHelper

      protected com.broadleafcommerce.search.index.core.document.helper.DocumentBuilderHelper getDocumentBuilderHelper()
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
    • getCloneMapper

      protected org.modelmapper.ModelMapper getCloneMapper()
    • getObjectMapper

      protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
    • getTenantService

      protected com.broadleafcommerce.search.index.core.service.IndexerTenantService getTenantService()
    • getTranslationProperties

      protected com.broadleafcommerce.search.autoconfigure.SearchCommonTranslationProperties getTranslationProperties()
    • setTranslationProperties

      @Autowired public void setTranslationProperties(com.broadleafcommerce.search.autoconfigure.SearchCommonTranslationProperties translationProperties)