Interface SolrIndexService

All Known Implementing Classes:
SolrIndexServiceImpl

public interface SolrIndexService
Service exposing several methods for creating a Solr index based on catalog product data.
Author:
Andre Azzolini (apazzolini), Jeff Fischer, Phillip Verheyden (phillipuniverse)
See Also:
  • Method Details

    • rebuildIndex

      void rebuildIndex() throws org.broadleafcommerce.common.exception.ServiceException, IOException

      Executes a full rebuild of the Solr index. This will rebuild the index on a separate core/collection and then swap out the active core/collection with the new version of the index (essentially replacing all documents that are currently in the index).

      The order of methods that are apart of rebuilding the entire index:

      1. preBuildIndex()
      2. buildIndex()
      3. postBuildIndex()
      Throws:
      IOException
      org.broadleafcommerce.common.exception.ServiceException
    • preBuildIndex

      void preBuildIndex() throws org.broadleafcommerce.common.exception.ServiceException
      Executed before we do any indexing when rebuilding the index. Usually this handles deleting the current index. This is called at the beginning of rebuildIndex()
      Throws:
      org.broadleafcommerce.common.exception.ServiceException
    • buildIndex

      void buildIndex() throws IOException, org.broadleafcommerce.common.exception.ServiceException

      Handles all the document building for the current index rebuild. This is where all of the SolrIndexOperation's need to be created, executed and the documents built and added to the Solr index

      This is the method that should be overridden to specify which operations should be run to build the correct index.

      Throws:
      IOException
      org.broadleafcommerce.common.exception.ServiceException
    • postBuildIndex

      void postBuildIndex() throws IOException, org.broadleafcommerce.common.exception.ServiceException
      Executed after we do any indexing when rebuilding the current index. Usually this handles optimizing the index and swapping the cores.
      Throws:
      IOException
      org.broadleafcommerce.common.exception.ServiceException
    • getReindexOperation

      SolrIndexOperation getReindexOperation()
      Creates the SolrIndexOperation for rebuilding the current index, used by buildIndex(). This is the primary index operation used to rebuild the index.
      Returns:
      a SolrIndexOperation capable of rebuilding the current index
    • executeSolrIndexOperation

      void executeSolrIndexOperation(SolrIndexOperation operation) throws org.broadleafcommerce.common.exception.ServiceException, IOException
      Executes the given operation in the correct method order
      Parameters:
      operation - the SolrIndexOperation that is to be executed
      Throws:
      org.broadleafcommerce.common.exception.ServiceException
      IOException
    • buildIncrementalIndex

      Collection<org.apache.solr.common.SolrInputDocument> buildIncrementalIndex(String collection, List<? extends Indexable> indexables, org.apache.solr.client.solrj.SolrClient solrServer) throws org.broadleafcommerce.common.exception.ServiceException
      Builds a set of Indexables against the given SolrServer
      Parameters:
      collection - The collection to be used for incremental indexing
      indexables - the list of items to index
      solrServer - if non-null, adds and commits the indexed documents to the server. If this is null, this will simply return the documents that were built from indexables
      Returns:
      the SolrInputDocuments that were built from the given indexables
      Throws:
      org.broadleafcommerce.common.exception.ServiceException
    • buildIncrementalIndex

      @Deprecated Collection<org.apache.solr.common.SolrInputDocument> buildIncrementalIndex(List<? extends Indexable> indexables, org.apache.solr.client.solrj.SolrClient solrServer) throws org.broadleafcommerce.common.exception.ServiceException
      Deprecated.
      Use buildIncrementalIndex(String, List, SolrClient) instead so that the collection that's being used can be customized otherwise the default collection will always be used. Generally use SolrConfiguration#getQueryCollectionName() or SolrConfiguration#getReindexCollectionName()
      Builds a set of Indexables against the given SolrServer
      Parameters:
      indexables - the list of items to index
      solrServer - if non-null, adds and commits the indexed documents to the server. If this is null, this will simply return the documents that were built from indexables
      Returns:
      the SolrInputDocuments that were built from the given indexables
      Throws:
      org.broadleafcommerce.common.exception.ServiceException
    • saveState

      Object[] saveState()
      Saves some global context that might be altered during indexing.
      Returns:
    • restoreState

      void restoreState(Object[] pack)
      Restores state that was saved prior to indexing that might have been altered.
      Parameters:
      pack -
      See Also:
    • optimizeIndex

      void optimizeIndex(String collection, org.apache.solr.client.solrj.SolrClient server) throws org.broadleafcommerce.common.exception.ServiceException, IOException
      Triggers the Solr optimize index function on the given server. This is typically called at the end of a rebuildIndex()
      Parameters:
      collection - The collection to optimize
      server - The server to use to optimze the given collection
      Throws:
      org.broadleafcommerce.common.exception.ServiceException
      IOException
    • optimizeIndex

      @Deprecated void optimizeIndex(org.apache.solr.client.solrj.SolrClient server) throws org.broadleafcommerce.common.exception.ServiceException, IOException
      Deprecated.
      Use optimizeIndex(String, SolrClient) instead so that the collection that's being used can be customized otherwise the default collection will always be used. Generally use SolrConfiguration#getQueryCollectionName() or SolrConfiguration#getReindexCollectionName()
      Triggers the Solr optimize index function on the given server. This is typically called at the end of a rebuildIndex()
      Parameters:
      server - The server to use to optimze the default collection
      Throws:
      org.broadleafcommerce.common.exception.ServiceException
      IOException
    • commit

      void commit(String collection, org.apache.solr.client.solrj.SolrClient server) throws org.broadleafcommerce.common.exception.ServiceException, IOException
      Allows a commit to be called. By default, the details of the commit will depend on system properties, including:

      solr.index.commit - if false, then no commit will be performed. autoCommit (and autoSoftCommit) should be configured in Solr. solr.index.softCommit - indicates if a soft commit should be performed solr.index.waitSearcher - indicates if the process should wait for a searcher to be configured solr.index.waitFlush - indicates if the process should wait for a flush to disk

      Parameters:
      collection - The collection to commit
      server - The server used to commit the specified collection
      Throws:
      org.broadleafcommerce.common.exception.ServiceException
      IOException
    • commit

      @Deprecated void commit(org.apache.solr.client.solrj.SolrClient server) throws org.broadleafcommerce.common.exception.ServiceException, IOException
      Deprecated.
      Use commit(String, SolrClient) instead so that the collection that's being used can be customized otherwise the default collection will always be used. Generally use SolrConfiguration#getQueryCollectionName() or SolrConfiguration#getReindexCollectionName()
      Allows a commit to be called. By default, the details of the commit will depend on system properties, including:

      solr.index.commit - if false, then no commit will be performed. autoCommit (and autoSoftCommit) should be configured in Solr. solr.index.softCommit - indicates if a soft commit should be performed solr.index.waitSearcher - indicates if the process should wait for a searcher to be configured solr.index.waitFlush - indicates if the process should wait for a flush to disk

      Parameters:
      server - The server used to commit the default collection
      Throws:
      org.broadleafcommerce.common.exception.ServiceException
      IOException
    • commit

      void commit(String collection, org.apache.solr.client.solrj.SolrClient server, boolean softCommit, boolean waitSearcher, boolean waitFlush) throws org.broadleafcommerce.common.exception.ServiceException, IOException
      This allows an external caller to force a commit to the SolrClient. See Solr Documentation for additional details. If using softCommit, you should ensure that a hardCommit is performed, either using autoCommit, or at the end of the commit process to flush the changes to the disk.

      Note that this method will force a commit even if solr.index.commit=false

      Parameters:
      collection - The collection to commit
      server - - the SolrClient to use to commit the provided collection
      softCommit - - soft commit is an efficient commit that does not write the data to the file system
      waitSearcher - - whether or not to wait for a new searcher to be created
      waitFlush - - whether or not to wait for a flush to disk.
      Throws:
      org.broadleafcommerce.common.exception.ServiceException
      IOException
    • commit

      @Deprecated void commit(org.apache.solr.client.solrj.SolrClient server, boolean softCommit, boolean waitSearcher, boolean waitFlush) throws org.broadleafcommerce.common.exception.ServiceException, IOException
      Deprecated.
      Use commit(String, SolrClient, boolean, boolean, boolean) instead so that the collection that's being used can be customized otherwise the default collection will always be used. Generally use SolrConfiguration#getQueryCollectionName() or SolrConfiguration#getReindexCollectionName()
      This allows an external caller to force a commit to the SolrClient. See Solr Documentation for additional details. If using softCommit, you should ensure that a hardCommit is performed, either using autoCommit, or at the end of the commit process to flush the changes to the disk.

      Note that this method will force a commit even if solr.index.commit=false

      Parameters:
      server - - the SolrClient to commit with
      softCommit - - soft commit is an efficient commit that does not write the data to the file system
      waitSearcher - - whether or not to wait for a new searcher to be created
      waitFlush - - whether or not to wait for a flush to disk.
      Throws:
      org.broadleafcommerce.common.exception.ServiceException
      IOException
    • deleteAllNamespaceDocuments

      void deleteAllNamespaceDocuments(String collection, org.apache.solr.client.solrj.SolrClient server) throws org.broadleafcommerce.common.exception.ServiceException
      Throws:
      org.broadleafcommerce.common.exception.ServiceException
    • deleteAllNamespaceDocuments

      @Deprecated void deleteAllNamespaceDocuments(org.apache.solr.client.solrj.SolrClient server) throws org.broadleafcommerce.common.exception.ServiceException
      Deprecated.
      Use deleteAllNamespaceDocuments(String, SolrClient) instead so that the collection that's being used can be customized otherwise the default collection will always be used. Generally use SolrConfiguration#getQueryCollectionName() or SolrConfiguration#getReindexCollectionName()
      Throws:
      org.broadleafcommerce.common.exception.ServiceException
    • deleteAllDocuments

      void deleteAllDocuments(String collection, org.apache.solr.client.solrj.SolrClient server) throws org.broadleafcommerce.common.exception.ServiceException
      Throws:
      org.broadleafcommerce.common.exception.ServiceException
    • deleteAllDocuments

      @Deprecated void deleteAllDocuments(org.apache.solr.client.solrj.SolrClient server) throws org.broadleafcommerce.common.exception.ServiceException
      Deprecated.
      Use deleteAllDocuments(String, SolrClient) instead so that the collection that's being used can be customized otherwise the default collection will always be used. Generally use SolrConfiguration#getQueryCollectionName() or SolrConfiguration#getReindexCollectionName()
      Throws:
      org.broadleafcommerce.common.exception.ServiceException
    • logDocuments

      void logDocuments(Collection<org.apache.solr.common.SolrInputDocument> documents)
      Prints out the docs to the trace logger
      Parameters:
      documents -
    • getAllLocales

      List<org.broadleafcommerce.common.locale.domain.Locale> getAllLocales()
      Returns:
      a list of all possible locale prefixes to consider
    • buildDocument

      org.apache.solr.common.SolrInputDocument buildDocument(Indexable indexable, List<IndexField> fields, List<org.broadleafcommerce.common.locale.domain.Locale> locales)
      Given a product, fields that relate to that product, and a list of locales and pricelists, builds a SolrInputDocument to be added to the Solr index.
      Parameters:
      indexable -
      fields -
      locales -
      Returns:
      the document
    • performCachedOperation

      void performCachedOperation(SolrIndexCachedOperation.CacheOperation cacheOperation) throws org.broadleafcommerce.common.exception.ServiceException
      SolrIndexService exposes #buildIncrementalIndex(int, int, boolean). By wrapping the call to this method inside of a SolrIndexCachedOperation.CacheOperation, a single cache will be used for all the contained calls to buildIncrementalIndex. Here's an example: performCachedOperation(new SolrIndexCachedOperation.CacheOperation() { @param cacheOperation the block of code to perform using a single cache for best performance @throws ServiceException @Override public void execute() throws ServiceException { int page = 0; while ((page * pageSize) < numProducts) { buildIncrementalIndex(page, pageSize); page++; } } }); Note rebuildIndex() already internally wraps its call using CacheOperation, so it is not necessary to call performCacheOperation for calls to rebuildIndex().
      Throws:
      org.broadleafcommerce.common.exception.ServiceException
    • attachIndexableDocumentFields

      void attachIndexableDocumentFields(org.apache.solr.common.SolrInputDocument document, Indexable indexable, List<IndexField> fields, List<org.broadleafcommerce.common.locale.domain.Locale> locales)
      Iterates through the fields for this Indexable and indexes any IndexFields
      Parameters:
      document -
      indexable -
      fields -
      locales -
    • deleteByQuery

      void deleteByQuery(String deleteQuery) throws org.apache.solr.client.solrj.SolrServerException, IOException
      Throws:
      org.apache.solr.client.solrj.SolrServerException
      IOException
    • addDocuments

      void addDocuments(Collection<org.apache.solr.common.SolrInputDocument> documents) throws IOException, org.apache.solr.client.solrj.SolrServerException
      Throws:
      IOException
      org.apache.solr.client.solrj.SolrServerException
    • logDeleteQuery

      void logDeleteQuery(String deleteQuery)
    • useLegacyIndexer

      boolean useLegacyIndexer()
      Indicates if this should be used. The alternative is to use CatalogSolrIndexUpdateService. By default, this is driven by the property, 'solr.catalog.useLegacySolrIndexer', which defaults to true.
      Returns: