Class SolrConfiguration

java.lang.Object
org.broadleafcommerce.core.search.service.solr.SolrConfiguration
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean

public class SolrConfiguration extends Object implements org.springframework.beans.factory.InitializingBean

Provides a class that will statically hold the Solr server.

This is initialized in SolrSearchServiceImpl and used in SolrIndexServiceImpl

Author:
Andre Azzolini (apazzolini)
  • Field Details

    • primaryName

      protected String primaryName
    • reindexName

      protected String reindexName
    • namespace

      protected String namespace
    • adminServer

      protected org.apache.solr.client.solrj.SolrClient adminServer
    • primaryServer

      protected org.apache.solr.client.solrj.SolrClient primaryServer
    • reindexServer

      protected org.apache.solr.client.solrj.SolrClient reindexServer
    • solrCloudConfigName

      protected String solrCloudConfigName
    • solrCloudNumShards

      protected Integer solrCloudNumShards
    • solrCloudNumReplicas

      protected Integer solrCloudNumReplicas
    • solrHomePath

      protected String solrHomePath
    • siteCollections

      @Value("${solr.index.site.collections:false}") protected boolean siteCollections
    • siteAliasBase

      @Value("${solr.index.site.alias.name:site}") protected String siteAliasBase
    • siteCollectionBase

      @Value("${solr.index.site.collection.name:blcSite}") protected String siteCollectionBase
  • Constructor Details

    • SolrConfiguration

      public SolrConfiguration(org.apache.solr.client.solrj.SolrClient solrServer, org.apache.solr.client.solrj.SolrClient reindexServer, org.apache.solr.client.solrj.SolrClient adminServer) throws IllegalStateException
      Sets up Solr using multiple clients, one primary, one for reindexing, and one admin to reduce down time during indexing. This constructor should be used when setting up HttpSolrClient since no collection names are being provided.

      The adminServer is just a reference to a SolrClient component for connecting to Solr. In newer versions of Solr, 4.4 and beyond, auto discovery of cores is provided. When using a stand-alone server or server cluster, the admin server, for swapping cores, is a different URL. For example, one needs to use http://solrserver:8983/solr, which formerly acted as the admin server AND as the primary core. As of Solr 4.4, one needs to specify the cores separately: http://solrserver:8983/solr/primary and http://solrserver:8983/solr/reindex, and use http://solrserver:8983/solr for swapping cores.

      Parameters:
      solrServer -
      reindexServer -
      adminServer -
      Throws:
      IllegalStateException
    • SolrConfiguration

      public SolrConfiguration(org.apache.solr.client.solrj.SolrClient solrServer, org.apache.solr.client.solrj.SolrClient reindexServer, org.apache.solr.client.solrj.SolrClient adminServer, String namespace) throws IllegalStateException
      Sets up Solr using multiple clients, one primary, one for reindexing, and one admin to reduce down time during indexing. This constructor should be used when setting up HttpSolrClient since no collection names are being provided. Namespace can be specified if managing multiple document sets within the same cores.

      The adminServer is just a reference to a SolrClient component for connecting to Solr. In newer versions of Solr, 4.4 and beyond, auto discovery of cores is provided. When using a stand-alone server or server cluster, the admin server, for swapping cores, is a different URL. For example, one needs to use http://solrserver:8983/solr, which formerly acted as the admin server AND as the primary core. As of Solr 4.4, one needs to specify the cores separately: http://solrserver:8983/solr/primary and http://solrserver:8983/solr/reindex, and use http://solrserver:8983/solr for swapping cores.

      Parameters:
      solrServer -
      reindexServer -
      adminServer -
      namespace -
      Throws:
      IllegalStateException
    • SolrConfiguration

      public SolrConfiguration(org.apache.solr.client.solrj.SolrClient solrServer, org.apache.solr.client.solrj.SolrClient reindexServer, org.apache.solr.client.solrj.SolrClient adminServer, String primaryCoreName, String reindexCoreName) throws IllegalStateException
      Sets up Solr using multiple clients, one primary, one for reindexing, and one admin to reduce down time during indexing. This constructor should be used when setting up LBHttpSolrClients because primaryCoreName and reindexCoreName need to be provided to SolrConfiguration.

      The adminServer is just a reference to a SolrClient component for connecting to Solr. In newer versions of Solr, 4.4 and beyond, auto discovery of cores is provided. When using a stand-alone server or server cluster, the admin server, for swapping cores, is a different URL. For example, one needs to use http://solrserver:8983/solr, which formerly acted as the admin server AND as the primary core. As of Solr 4.4, one needs to specify the cores separately: http://solrserver:8983/solr/primary and http://solrserver:8983/solr/reindex, and use http://solrserver:8983/solr for swapping cores.

      Parameters:
      solrServer -
      reindexServer -
      adminServer -
      primaryCoreName -
      reindexCoreName -
      Throws:
      IllegalStateException
    • SolrConfiguration

      public SolrConfiguration(org.apache.solr.client.solrj.SolrClient solrServer, org.apache.solr.client.solrj.SolrClient reindexServer, org.apache.solr.client.solrj.SolrClient adminServer, String primaryCoreName, String reindexCoreName, String namespace) throws IllegalStateException
      Sets up Solr using multiple clients, one primary, one for reindexing, and one admin to reduce down time during indexing. This constructor should be used when setting up LBHttpSolrClients because primaryCoreName and reindexCoreName need to be provided to SolrConfiguration. Namespace can be specified if managing multiple document sets within the same cores.

      The adminServer is just a reference to a SolrClient component for connecting to Solr. In newer versions of Solr, 4.4 and beyond, auto discovery of cores is provided. When using a stand-alone server or server cluster, the admin server, for swapping cores, is a different URL. For example, one needs to use http://solrserver:8983/solr, which formerly acted as the admin server AND as the primary core. As of Solr 4.4, one needs to specify the cores separately: http://solrserver:8983/solr/primary and http://solrserver:8983/solr/reindex, and use http://solrserver:8983/solr for swapping cores.

      Parameters:
      solrServer -
      reindexServer -
      adminServer -
      primaryCoreName -
      reindexCoreName -
      namespace -
      Throws:
      IllegalStateException
    • SolrConfiguration

      public SolrConfiguration(org.apache.solr.client.solrj.SolrClient solrServer, org.apache.solr.client.solrj.SolrClient reindexServer, String solrCloudConfigName, int solrCloudNumShards) throws IllegalStateException
      This constructor should be used to set up Solr Cloud using solr cloud config name, number of cloud shards, and multiple clients, one primary, and one for reindexing to reduce down time during indexing. Be sure to set the defaultCollection on the SolrClients correctly before passing them to this constructor.
      Parameters:
      solrServer -
      reindexServer -
      solrCloudConfigName -
      solrCloudNumShards -
      Throws:
      IllegalStateException
    • SolrConfiguration

      public SolrConfiguration(org.apache.solr.client.solrj.impl.CloudSolrClient solrServer, org.apache.solr.client.solrj.impl.CloudSolrClient reindexServer, String solrCloudConfigName, int solrCloudNumShards, int replicationFactor) throws IllegalStateException
      Parameters:
      solrServer -
      reindexServer -
      solrCloudConfigName -
      solrCloudNumShards -
      Throws:
      IllegalStateException
    • SolrConfiguration

      public SolrConfiguration(org.apache.solr.client.solrj.SolrClient solrServer, org.apache.solr.client.solrj.SolrClient reindexServer, String solrCloudConfigName, int solrCloudNumShards, String namespace) throws IllegalStateException
      This constructor should be used to set up Solr Cloud using solr cloud config name, number of cloud shards, and multiple clients, one primary, and one for reindexing to reduce down time during indexing. Be sure to set the defaultCollection on the SolrClients correctly before passing them to this constructor. Namespace can be specified if managing multiple document sets within the same collections.
      Parameters:
      solrServer -
      reindexServer -
      solrCloudConfigName -
      solrCloudNumShards -
      namespace -
      Throws:
      IllegalStateException
  • Method Details

    • getPrimaryName

      public String getPrimaryName()
    • setPrimaryName

      public void setPrimaryName(String primaryName)
    • getReindexName

      public String getReindexName()
    • setReindexName

      public void setReindexName(String reindex)
    • getSolrCloudConfigName

      public String getSolrCloudConfigName()
    • setSolrCloudConfigName

      public void setSolrCloudConfigName(String solrCloudConfigName)
    • getSolrCloudNumShards

      public Integer getSolrCloudNumShards()
    • setSolrCloudNumShards

      public void setSolrCloudNumShards(Integer solrCloudNumShards)
    • setSolrCloudNumShards

      public void setSolrCloudNumShards(int solrCloudNumShards)
    • getSolrCloudNumReplicas

      public Integer getSolrCloudNumReplicas()
    • setSolrCloudNumReplicas

      public void setSolrCloudNumReplicas(Integer solrCloudNumReplicas)
    • getSolrHomePath

      public String getSolrHomePath()
    • setSolrHomePath

      public void setSolrHomePath(String solrHomePath)
    • getNamespace

      public String getNamespace()
    • setNamespace

      public void setNamespace(String namespace)
    • getAdminServer

      public org.apache.solr.client.solrj.SolrClient getAdminServer()
      The adminServer is just a reference to a SolrClient component for connecting to Solr. In newer versions of Solr, 4.4 and beyond, auto discovery of cores is provided. When using a stand-alone server or server cluster, the admin server, for swapping cores, is a different URL. For example, one needs to use http://solrserver:8983/solr, which formerly acted as the admin server AND as the primary core. As of Solr 4.4, one needs to specify the cores separately: http://solrserver:8983/solr/primary and http://solrserver:8983/solr/reindex, and use http://solrserver:8983/solr for swapping cores.

      By default, this method attempts to return an admin server if configured. Otherwise, it returns the primary server if the admin server is null, which is backwards compatible with the way that BLC worked prior to this change.

      Returns:
    • setAdminServer

      public void setAdminServer(org.apache.solr.client.solrj.SolrClient server)
      Sets the admin SolrClient instance to communicate with Solr for administrative reasons, like swapping cores. This is typically one of the following: org.apache.solr.client.solrj.embedded.EmbeddedSolrServer, org.apache.solr.client.solrj.impl.HttpSolrServer, org.apache.solr.client.solrj.impl.LBHttpSolrServer, or org.apache.solr.client.solrj.impl.CloudSolrClient

      This should not typically need to be set unless using a stand-alone configuration, where the path to the /admin URI is different than the core URI. This should not typically be set for EmbeddedSolrServer or CloudSolrClient.

      Parameters:
      server -
    • getServer

      public org.apache.solr.client.solrj.SolrClient getServer()
      Returns:
      the primary Solr server
    • setServer

      public void setServer(org.apache.solr.client.solrj.SolrClient server) throws IllegalStateException
      Sets the primary SolrClient instance to communicate with Solr. This is typically one of the following: org.apache.solr.client.solrj.embedded.EmbeddedSolrClient, org.apache.solr.client.solrj.impl.HttpSolrClient, org.apache.solr.client.solrj.impl.LBHttpSolrClient, or org.apache.solr.client.solrj.impl.CloudSolrClient
      Parameters:
      server - SolrClient
      Throws:
      IllegalStateException
    • getReindexServer

      public org.apache.solr.client.solrj.SolrClient getReindexServer()
      Returns:
      the primary server if isSingleCoreMode(), else the reindex server
    • setReindexServer

      public void setReindexServer(org.apache.solr.client.solrj.SolrClient server) throws IllegalStateException
      Sets the SolrClient instance that points to the reindex core for the purpose of doing a full reindex, while the primary core is still serving serving requests. This is typically one of the following: org.apache.solr.client.solrj.embedded.EmbeddedSolrServer, org.apache.solr.client.solrj.impl.HttpSolrServer, org.apache.solr.client.solrj.impl.LBHttpSolrServer, or org.apache.solr.client.solrj.impl.CloudSolrClient
      Parameters:
      server -
      Throws:
      IllegalStateException
    • isSingleCoreMode

      public boolean isSingleCoreMode()
      Returns:
      if this Solr context has a reindex server set not
    • isSolrCloudMode

      public boolean isSolrCloudMode()
    • afterPropertiesSet

      public void afterPropertiesSet() throws org.apache.solr.client.solrj.SolrServerException, IOException, IllegalStateException
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      org.apache.solr.client.solrj.SolrServerException
      IOException
      IllegalStateException
    • validateCloudSolrClients

      protected void validateCloudSolrClients(org.apache.solr.client.solrj.impl.CloudSolrClient primary, org.apache.solr.client.solrj.impl.CloudSolrClient reindex)
    • reloadCollectionNames

      protected void reloadCollectionNames(org.apache.solr.client.solrj.impl.CloudSolrClient primary, org.apache.solr.client.solrj.impl.CloudSolrClient reindex) throws org.apache.solr.client.solrj.SolrServerException, IOException
      Throws:
      org.apache.solr.client.solrj.SolrServerException
      IOException
    • aliasCollectionMap

      protected Map<String,String> aliasCollectionMap(org.apache.solr.client.solrj.impl.CloudSolrClient client) throws org.apache.solr.client.solrj.SolrServerException, IOException
      Throws:
      org.apache.solr.client.solrj.SolrServerException
      IOException
    • getSiteServer

      public org.apache.solr.client.solrj.SolrClient getSiteServer()
    • getSiteReindexServer

      public org.apache.solr.client.solrj.SolrClient getSiteReindexServer()
    • createCollectionIfNotExist

      protected void createCollectionIfNotExist(org.apache.solr.client.solrj.impl.CloudSolrClient client, String collectionName)
    • createCollection

      protected void createCollection(org.apache.solr.client.solrj.impl.CloudSolrClient client, String collectionName)
    • solrCloudConfigName

      protected String solrCloudConfigName(org.apache.solr.client.solrj.impl.CloudSolrClient client)
    • createAliasIfNotExist

      protected void createAliasIfNotExist(org.apache.solr.client.solrj.impl.CloudSolrClient client, String collectionName, String aliasName)
    • createAlias

      protected void createAlias(org.apache.solr.client.solrj.impl.CloudSolrClient client, String collectionName, String aliasName)
    • getSiteAliasName

      protected String getSiteAliasName(org.broadleafcommerce.common.site.domain.Site site)
      Parameters:
      site - the Site
      Returns:
      the alias name for the given Site
    • getSiteCollectionName

      protected String getSiteCollectionName(org.broadleafcommerce.common.site.domain.Site site)
      Parameters:
      site - the Site
      Returns:
      the collection name for the given Site
    • getSiteReindexAliasName

      protected String getSiteReindexAliasName(org.broadleafcommerce.common.site.domain.Site site)
      Parameters:
      site - the Site
      Returns:
      the reindex alias name for the given Site
    • getSiteReindexCollectionName

      protected String getSiteReindexCollectionName(org.broadleafcommerce.common.site.domain.Site site)
      Parameters:
      site - the Site
      Returns:
      the reindex collection name for the given Site
    • getSiteAliasBase

      protected String getSiteAliasBase()
    • setSiteAliasBase

      public void setSiteAliasBase(String siteAliasBase)
    • getSiteCollectionBase

      protected String getSiteCollectionBase()
    • setSiteCollectionBase

      public void setSiteCollectionBase(String siteCollectionBase)
    • isSiteCollections

      public boolean isSiteCollections()
      Returns:
      whether to index a separate collection per site
    • setSiteCollections

      public void setSiteCollections(boolean siteCollections)
    • getQueryCollectionName

      public String getQueryCollectionName()
    • getReindexCollectionName

      public String getReindexCollectionName()
    • determineCoreName

      protected String determineCoreName(org.apache.solr.client.solrj.impl.HttpSolrClient httpSolrClient)
    • destroy

      public void destroy() throws Exception
      Throws:
      Exception