Class SolrIndexServiceImpl
- All Implemented Interfaces:
SolrIndexService,org.springframework.beans.factory.InitializingBean
- Author:
- Andre Azzolini (apazzolini), Jeff Fischer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CatalogServiceprotected booleanprotected booleanprotected SolrIndexServiceExtensionManagerprotected FieldDaoprotected IndexFieldDaoprotected org.broadleafcommerce.common.locale.service.LocaleServiceprotected intprotected ProductDaoprotected org.broadleafcommerce.common.sandbox.SandBoxHelperprotected SearchFacetDaoprotected SolrHelperServiceprotected booleanprotected SolrConfigurationprotected SolrIndexDaoprotected org.springframework.transaction.PlatformTransactionManagerprotected booleanprotected booleanprotected boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDocuments(Collection<org.apache.solr.common.SolrInputDocument> documents) voidprotected voidattachAdditionalDocumentFields(Indexable indexable, org.apache.solr.common.SolrInputDocument document) Implementors can extend this and override this method to add additional fields to the Solr document.protected voidattachBasicDocumentFields(Indexable indexable, org.apache.solr.common.SolrInputDocument document) voidattachIndexableDocumentFields(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 IndexFieldsorg.apache.solr.common.SolrInputDocumentbuildDocument(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.protected voidbuildFullCategoryHierarchy(org.apache.solr.common.SolrInputDocument document, CatalogStructure cache, Long categoryId, Set<Long> indexedParents) Walk the category hierarchy upwards, adding a field for each level to the solr documentprotected LongbuildIncrementalIndex(int pageSize, Long lastId, SolrIndexOperation operation) Collection<org.apache.solr.common.SolrInputDocument>buildIncrementalIndex(String collection, List<? extends Indexable> indexables, org.apache.solr.client.solrj.SolrClient solrServer) Builds a set ofIndexables against the givenSolrServerCollection<org.apache.solr.common.SolrInputDocument>buildIncrementalIndex(List<? extends Indexable> indexables, org.apache.solr.client.solrj.SolrClient solrServer) Builds a set ofIndexables against the givenSolrServervoidHandles all the document building for the current index rebuild.protected StringbuildPageNumberMessage(int page, Long totalPages) voidAllows a commit to be called.voidcommit(String collection, org.apache.solr.client.solrj.SolrClient server, boolean softCommit, boolean waitSearcher, boolean waitFlush) This allows an external caller to force a commit to the SolrClient.voidcommit(org.apache.solr.client.solrj.SolrClient server) Allows a commit to be called.voidcommit(org.apache.solr.client.solrj.SolrClient server, boolean softCommit, boolean waitSearcher, boolean waitFlush) This allows an external caller to force a commit to the SolrClient.protected LongconvertDisplayOrderToLong(CatalogStructure cache, String displayOrderKey) We multiply the BigDecimal by 1,000,000 to maintain any possible decimals in use the displayOrder value.protected StringconvertToMappedProperty(String propertyName, String listPropertyName, String mapPropertyName) Deprecated.see SolrHelperService.getPropertyValue()protected Longprotected voidDeprecated.usedeleteAllReindexCoreDocuments()insteadvoiddeleteAllDocuments(String collection, org.apache.solr.client.solrj.SolrClient server) voiddeleteAllDocuments(org.apache.solr.client.solrj.SolrClient server) voiddeleteAllNamespaceDocuments(String collection, org.apache.solr.client.solrj.SolrClient server) voiddeleteAllNamespaceDocuments(org.apache.solr.client.solrj.SolrClient server) protected voidThis method deletes all of the documents fromSolrContext#getReindexServer()voiddeleteByQuery(String deleteQuery) voidexecuteSolrIndexOperation(SolrIndexOperation operation) Executes the given operation in the correct method orderList<org.broadleafcommerce.common.locale.domain.Locale>getPropertyValues(Indexable indexedItem, Field field, FieldType fieldType, List<org.broadleafcommerce.common.locale.domain.Locale> locales) Returns a map of prefix to value for the requested attributes.Creates the SolrIndexOperation for rebuilding the current index, used bySolrIndexService.buildIndex().protected longgetTotalPageCount(Long numItemsToIndex) voidlogDeleteQuery(String deleteQuery) voidlogDocuments(Collection<org.apache.solr.common.SolrInputDocument> documents) Prints out the docs to the trace loggervoidoptimizeIndex(String collection, org.apache.solr.client.solrj.SolrClient server) Triggers the Solr optimize index function on the given server.voidoptimizeIndex(org.apache.solr.client.solrj.SolrClient server) Triggers the Solr optimize index function on the given server.voidperformCachedOperation(SolrIndexCachedOperation.CacheOperation cacheOperation) SolrIndexService exposes#buildIncrementalIndex(int, int, boolean).voidExecuted after we do any indexing when rebuilding the current index.voidExecuted before we do any indexing when rebuilding the index.readAllActiveIndexables(int pageSize, Long lastId) voidExecutes a full rebuild of the Solr index.voidrestoreState(Object[] pack) Restores state that was saved prior to indexing that might have been altered.Object[]Saves some global context that might be altered during indexing.booleanIndicates if this should be used.
-
Field Details
-
solrConfiguration
@Qualifier("blCatalogSolrConfiguration") @Autowired(required=false) protected SolrConfiguration solrConfiguration -
errorOnConcurrentReIndex
@Value("${solr.index.errorOnConcurrentReIndex}") protected boolean errorOnConcurrentReIndex -
pageSize
@Value("${solr.index.product.pageSize}") protected int pageSize -
commit
@Value("${solr.index.commit}") protected boolean commit -
softCommit
@Value("${solr.index.softCommit}") protected boolean softCommit -
waitSearcher
@Value("${solr.index.waitSearcher}") protected boolean waitSearcher -
waitFlush
@Value("${solr.index.waitFlush}") protected boolean waitFlush -
useLegacySolrIndexer
@Value("${solr.catalog.useLegacySolrIndexer:true}") protected boolean useLegacySolrIndexer -
productDao
-
catalogService
-
fieldDao
-
localeService
protected org.broadleafcommerce.common.locale.service.LocaleService localeService -
shs
-
extensionManager
-
transactionManager
protected org.springframework.transaction.PlatformTransactionManager transactionManager -
solrIndexDao
-
sandBoxHelper
protected org.broadleafcommerce.common.sandbox.SandBoxHelper sandBoxHelper -
searchFacetDao
-
indexFieldDao
-
-
Constructor Details
-
SolrIndexServiceImpl
public SolrIndexServiceImpl()
-
-
Method Details
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-
performCachedOperation
public void performCachedOperation(SolrIndexCachedOperation.CacheOperation cacheOperation) throws org.broadleafcommerce.common.exception.ServiceException Description copied from interface:SolrIndexServiceSolrIndexService exposes#buildIncrementalIndex(int, int, boolean). By wrapping the call to this method inside of aSolrIndexCachedOperation.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++; } } });NoteSolrIndexService.rebuildIndex()already internally wraps its call using CacheOperation, so it is not necessary to call performCacheOperation for calls to rebuildIndex().- Specified by:
performCachedOperationin interfaceSolrIndexService- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
rebuildIndex
public void rebuildIndex() throws org.broadleafcommerce.common.exception.ServiceException, IOExceptionDescription copied from interface:SolrIndexServiceExecutes 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:
- Specified by:
rebuildIndexin interfaceSolrIndexService- Throws:
org.broadleafcommerce.common.exception.ServiceExceptionIOException
-
preBuildIndex
public void preBuildIndex() throws org.broadleafcommerce.common.exception.ServiceExceptionDescription copied from interface:SolrIndexServiceExecuted before we do any indexing when rebuilding the index. Usually this handles deleting the current index. This is called at the beginning ofSolrIndexService.rebuildIndex()- Specified by:
preBuildIndexin interfaceSolrIndexService- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
buildIndex
public void buildIndex() throws IOException, org.broadleafcommerce.common.exception.ServiceExceptionDescription copied from interface:SolrIndexServiceHandles 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.
- Specified by:
buildIndexin interfaceSolrIndexService- Throws:
IOExceptionorg.broadleafcommerce.common.exception.ServiceException
-
postBuildIndex
public void postBuildIndex() throws IOException, org.broadleafcommerce.common.exception.ServiceExceptionDescription copied from interface:SolrIndexServiceExecuted after we do any indexing when rebuilding the current index. Usually this handles optimizing the index and swapping the cores.- Specified by:
postBuildIndexin interfaceSolrIndexService- Throws:
IOExceptionorg.broadleafcommerce.common.exception.ServiceException
-
getReindexOperation
Description copied from interface:SolrIndexServiceCreates the SolrIndexOperation for rebuilding the current index, used bySolrIndexService.buildIndex(). This is the primary index operation used to rebuild the index.- Specified by:
getReindexOperationin interfaceSolrIndexService- Returns:
- a SolrIndexOperation capable of rebuilding the current index
-
executeSolrIndexOperation
public void executeSolrIndexOperation(SolrIndexOperation operation) throws org.broadleafcommerce.common.exception.ServiceException, IOException Description copied from interface:SolrIndexServiceExecutes the given operation in the correct method order- Specified by:
executeSolrIndexOperationin interfaceSolrIndexService- Parameters:
operation- the SolrIndexOperation that is to be executed- Throws:
org.broadleafcommerce.common.exception.ServiceExceptionIOException
-
getTotalPageCount
-
buildPageNumberMessage
-
countIndexableItems
- Returns:
-
deleteAllDocuments
@Deprecated protected void deleteAllDocuments() throws org.broadleafcommerce.common.exception.ServiceExceptionDeprecated.usedeleteAllReindexCoreDocuments()insteadThis method deletes all of the documents from
SolrContext#getReindexServer()- Throws:
org.broadleafcommerce.common.exception.ServiceException- if there was a problem removing the documents
-
deleteAllReindexCoreDocuments
protected void deleteAllReindexCoreDocuments() throws org.broadleafcommerce.common.exception.ServiceExceptionThis method deletes all of the documents from
SolrContext#getReindexServer()- Throws:
org.broadleafcommerce.common.exception.ServiceException- if there was a problem removing the documents
-
deleteAllNamespaceDocuments
public void deleteAllNamespaceDocuments(String collection, org.apache.solr.client.solrj.SolrClient server) throws org.broadleafcommerce.common.exception.ServiceException - Specified by:
deleteAllNamespaceDocumentsin interfaceSolrIndexService- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
deleteAllDocuments
public void deleteAllDocuments(String collection, org.apache.solr.client.solrj.SolrClient server) throws org.broadleafcommerce.common.exception.ServiceException - Specified by:
deleteAllDocumentsin interfaceSolrIndexService- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
buildIncrementalIndex
protected Long buildIncrementalIndex(int pageSize, Long lastId, SolrIndexOperation operation) throws org.broadleafcommerce.common.exception.ServiceException - Throws:
org.broadleafcommerce.common.exception.ServiceException
-
buildIncrementalIndex
public 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 Description copied from interface:SolrIndexServiceBuilds a set ofIndexables against the givenSolrServer- Specified by:
buildIncrementalIndexin interfaceSolrIndexService- Parameters:
collection- The collection to be used for incremental indexingindexables- the list of items to indexsolrServer- 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
-
readAllActiveIndexables
-
getAllLocales
- Specified by:
getAllLocalesin interfaceSolrIndexService- Returns:
- a list of all possible locale prefixes to consider
-
buildDocument
public org.apache.solr.common.SolrInputDocument buildDocument(Indexable indexable, List<IndexField> fields, List<org.broadleafcommerce.common.locale.domain.Locale> locales) Description copied from interface:SolrIndexServiceGiven 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.- Specified by:
buildDocumentin interfaceSolrIndexService- Returns:
- the document
-
attachIndexableDocumentFields
public void attachIndexableDocumentFields(org.apache.solr.common.SolrInputDocument document, Indexable indexable, List<IndexField> fields, List<org.broadleafcommerce.common.locale.domain.Locale> locales) Description copied from interface:SolrIndexServiceIterates through the fields for this Indexable and indexes any IndexFields- Specified by:
attachIndexableDocumentFieldsin interfaceSolrIndexService
-
attachAdditionalDocumentFields
protected void attachAdditionalDocumentFields(Indexable indexable, org.apache.solr.common.SolrInputDocument document) Implementors can extend this and override this method to add additional fields to the Solr document.- Parameters:
indexable-document-
-
attachBasicDocumentFields
protected void attachBasicDocumentFields(Indexable indexable, org.apache.solr.common.SolrInputDocument document) -
buildFullCategoryHierarchy
protected void buildFullCategoryHierarchy(org.apache.solr.common.SolrInputDocument document, CatalogStructure cache, Long categoryId, Set<Long> indexedParents) Walk the category hierarchy upwards, adding a field for each level to the solr document- Parameters:
document- the solr document for the productcache- the catalog structure cachecategoryId- the current category id
-
getPropertyValues
protected Map<String,Object> getPropertyValues(Indexable indexedItem, Field field, FieldType fieldType, List<org.broadleafcommerce.common.locale.domain.Locale> locales) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Returns a map of prefix to value for the requested attributes. For example, if the requested field corresponds to a Sku's description and the locales list has the en_US locale and the es_ES locale, the resulting map could be{ "en_US" : "A description", "es_ES" : "Una descripcion" }
- Parameters:
indexedItem-field-fieldType-locales-- Returns:
- the value of the property
- Throws:
IllegalAccessExceptionInvocationTargetExceptionNoSuchMethodException
-
convertToMappedProperty
@Deprecated protected String convertToMappedProperty(String propertyName, String listPropertyName, String mapPropertyName) Deprecated.see SolrHelperService.getPropertyValue()Converts a propertyName to one that is able to reference inside a map. For example, consider the property in Product that references a List, "productAttributes". Also consider the utility method in Product called "mappedProductAttributes", which returns a map of the ProductAttributes keyed by the name property in the ProductAttribute. Given the parameters "productAttributes.heatRange", "productAttributes", "mappedProductAttributes" (which would represent a property called "productAttributes.heatRange" that references a specific ProductAttribute inside of a product whose "name" property is equal to "heatRange", this method will convert this property to mappedProductAttributes(heatRange).value, which is then usable by the standard beanutils PropertyUtils class to get the value. - Parameters:
propertyName-listPropertyName-mapPropertyName-- Returns:
- the converted property name
-
saveState
Description copied from interface:SolrIndexServiceSaves some global context that might be altered during indexing.- Specified by:
saveStatein interfaceSolrIndexService- Returns:
-
restoreState
Description copied from interface:SolrIndexServiceRestores state that was saved prior to indexing that might have been altered.- Specified by:
restoreStatein interfaceSolrIndexService- See Also:
-
optimizeIndex
public void optimizeIndex(String collection, org.apache.solr.client.solrj.SolrClient server) throws org.broadleafcommerce.common.exception.ServiceException, IOException Description copied from interface:SolrIndexServiceTriggers the Solr optimize index function on the given server. This is typically called at the end of aSolrIndexService.rebuildIndex()- Specified by:
optimizeIndexin interfaceSolrIndexService- Parameters:
collection- The collection to optimizeserver- The server to use to optimze the given collection- Throws:
org.broadleafcommerce.common.exception.ServiceExceptionIOException
-
commit
public void commit(String collection, org.apache.solr.client.solrj.SolrClient server) throws org.broadleafcommerce.common.exception.ServiceException, IOException Description copied from interface:SolrIndexServiceAllows 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
- Specified by:
commitin interfaceSolrIndexService- Parameters:
collection- The collection to commitserver- The server used to commit the specified collection- Throws:
org.broadleafcommerce.common.exception.ServiceExceptionIOException
-
commit
public void commit(String collection, org.apache.solr.client.solrj.SolrClient server, boolean softCommit, boolean waitSearcher, boolean waitFlush) throws org.broadleafcommerce.common.exception.ServiceException, IOException Description copied from interface:SolrIndexServiceThis 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
- Specified by:
commitin interfaceSolrIndexService- Parameters:
collection- The collection to commitserver- - the SolrClient to use to commit the provided collectionsoftCommit- - soft commit is an efficient commit that does not write the data to the file systemwaitSearcher- - whether or not to wait for a new searcher to be createdwaitFlush- - whether or not to wait for a flush to disk.- Throws:
org.broadleafcommerce.common.exception.ServiceExceptionIOException
-
logDocuments
Description copied from interface:SolrIndexServicePrints out the docs to the trace logger- Specified by:
logDocumentsin interfaceSolrIndexService
-
convertDisplayOrderToLong
We multiply the BigDecimal by 1,000,000 to maintain any possible decimals in use the displayOrder value.- Parameters:
cache-displayOrderKey-- Returns:
-
deleteByQuery
public void deleteByQuery(String deleteQuery) throws org.apache.solr.client.solrj.SolrServerException, IOException - Specified by:
deleteByQueryin interfaceSolrIndexService- Throws:
org.apache.solr.client.solrj.SolrServerExceptionIOException
-
addDocuments
public void addDocuments(Collection<org.apache.solr.common.SolrInputDocument> documents) throws IOException, org.apache.solr.client.solrj.SolrServerException - Specified by:
addDocumentsin interfaceSolrIndexService- Throws:
IOExceptionorg.apache.solr.client.solrj.SolrServerException
-
logDeleteQuery
- Specified by:
logDeleteQueryin interfaceSolrIndexService
-
buildIncrementalIndex
public Collection<org.apache.solr.common.SolrInputDocument> buildIncrementalIndex(List<? extends Indexable> indexables, org.apache.solr.client.solrj.SolrClient solrServer) throws org.broadleafcommerce.common.exception.ServiceException Description copied from interface:SolrIndexServiceBuilds a set ofIndexables against the givenSolrServer- Specified by:
buildIncrementalIndexin interfaceSolrIndexService- Parameters:
indexables- the list of items to indexsolrServer- 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
-
optimizeIndex
public void optimizeIndex(org.apache.solr.client.solrj.SolrClient server) throws org.broadleafcommerce.common.exception.ServiceException, IOException Description copied from interface:SolrIndexServiceTriggers the Solr optimize index function on the given server. This is typically called at the end of aSolrIndexService.rebuildIndex()- Specified by:
optimizeIndexin interfaceSolrIndexService- Parameters:
server- The server to use to optimze the default collection- Throws:
org.broadleafcommerce.common.exception.ServiceExceptionIOException
-
commit
public void commit(org.apache.solr.client.solrj.SolrClient server) throws org.broadleafcommerce.common.exception.ServiceException, IOException Description copied from interface:SolrIndexServiceAllows 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
- Specified by:
commitin interfaceSolrIndexService- Parameters:
server- The server used to commit the default collection- Throws:
org.broadleafcommerce.common.exception.ServiceExceptionIOException
-
commit
public void commit(org.apache.solr.client.solrj.SolrClient server, boolean softCommit, boolean waitSearcher, boolean waitFlush) throws org.broadleafcommerce.common.exception.ServiceException, IOException Description copied from interface:SolrIndexServiceThis 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
- Specified by:
commitin interfaceSolrIndexService- Parameters:
server- - the SolrClient to commit withsoftCommit- - soft commit is an efficient commit that does not write the data to the file systemwaitSearcher- - whether or not to wait for a new searcher to be createdwaitFlush- - whether or not to wait for a flush to disk.- Throws:
org.broadleafcommerce.common.exception.ServiceExceptionIOException
-
deleteAllNamespaceDocuments
public void deleteAllNamespaceDocuments(org.apache.solr.client.solrj.SolrClient server) throws org.broadleafcommerce.common.exception.ServiceException - Specified by:
deleteAllNamespaceDocumentsin interfaceSolrIndexService- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
deleteAllDocuments
public void deleteAllDocuments(org.apache.solr.client.solrj.SolrClient server) throws org.broadleafcommerce.common.exception.ServiceException - Specified by:
deleteAllDocumentsin interfaceSolrIndexService- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
useLegacyIndexer
public boolean useLegacyIndexer()Description copied from interface:SolrIndexServiceIndicates if this should be used. The alternative is to useCatalogSolrIndexUpdateService. By default, this is driven by the property, 'solr.catalog.useLegacySolrIndexer', which defaults to true.- Specified by:
useLegacyIndexerin interfaceSolrIndexService- Returns:
-