Interface SolrIndexService
- All Known Implementing Classes:
SolrIndexServiceImpl
- Author:
- Andre Azzolini (apazzolini), Jeff Fischer, Phillip Verheyden (phillipuniverse)
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddDocuments(Collection<org.apache.solr.common.SolrInputDocument> documents) voidattachIndexableDocumentFields(org.apache.solr.common.SolrInputDocument document, Indexable indexable, List<IndexField> fields, List<Locale> locales) Iterates through the fields for this Indexable and indexes any IndexFieldsorg.apache.solr.common.SolrInputDocumentbuildDocument(Indexable indexable, List<IndexField> fields, List<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.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) Deprecated.voidHandles all the document building for the current index rebuild.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) Deprecated.Usecommit(String, SolrClient)instead so that the collection that's being used can be customized otherwise the default collection will always be used.voidcommit(org.apache.solr.client.solrj.SolrClient server, boolean softCommit, boolean waitSearcher, boolean waitFlush) Deprecated.Usecommit(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.voiddeleteAllDocuments(String collection, org.apache.solr.client.solrj.SolrClient server) voiddeleteAllDocuments(org.apache.solr.client.solrj.SolrClient server) Deprecated.UsedeleteAllDocuments(String, SolrClient)instead so that the collection that's being used can be customized otherwise the default collection will always be used.voiddeleteAllNamespaceDocuments(String collection, org.apache.solr.client.solrj.SolrClient server) voiddeleteAllNamespaceDocuments(org.apache.solr.client.solrj.SolrClient server) Deprecated.UsedeleteAllNamespaceDocuments(String, SolrClient)instead so that the collection that's being used can be customized otherwise the default collection will always be used.voiddeleteByQuery(String deleteQuery) voidexecuteSolrIndexOperation(SolrIndexOperation operation) Executes the given operation in the correct method orderCreates the SolrIndexOperation for rebuilding the current index, used bybuildIndex().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) Deprecated.UseoptimizeIndex(String, SolrClient)instead so that the collection that's being used can be customized otherwise the default collection will always be used.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.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.
-
Method Details
-
rebuildIndex
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:
- Throws:
IOExceptionServiceException
-
preBuildIndex
Executed before we do any indexing when rebuilding the index. Usually this handles deleting the current index. This is called at the beginning ofrebuildIndex()- Throws:
ServiceException
-
buildIndex
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:
IOExceptionServiceException
-
postBuildIndex
Executed after we do any indexing when rebuilding the current index. Usually this handles optimizing the index and swapping the cores.- Throws:
IOExceptionServiceException
-
getReindexOperation
SolrIndexOperation getReindexOperation()Creates the SolrIndexOperation for rebuilding the current index, used bybuildIndex(). This is the primary index operation used to rebuild the index.- Returns:
- a SolrIndexOperation capable of rebuilding the current index
-
executeSolrIndexOperation
Executes the given operation in the correct method order- Parameters:
operation- the SolrIndexOperation that is to be executed- Throws:
ServiceExceptionIOException
-
buildIncrementalIndex
Collection<org.apache.solr.common.SolrInputDocument> buildIncrementalIndex(String collection, List<? extends Indexable> indexables, org.apache.solr.client.solrj.SolrClient solrServer) throws ServiceException Builds a set ofIndexables against the givenSolrServer- 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:
ServiceException
-
buildIncrementalIndex
@Deprecated Collection<org.apache.solr.common.SolrInputDocument> buildIncrementalIndex(List<? extends Indexable> indexables, org.apache.solr.client.solrj.SolrClient solrServer) throws ServiceException Deprecated.UsebuildIncrementalIndex(String, List, SolrClient)instead so that the collection that's being used can be customized otherwise the default collection will always be used. Generally useSolrConfiguration#getQueryCollectionName()orSolrConfiguration#getReindexCollectionName()Builds a set ofIndexables against the givenSolrServer- 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:
ServiceException
-
saveState
Object[] saveState()Saves some global context that might be altered during indexing.- Returns:
-
restoreState
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 ServiceException, IOException Triggers the Solr optimize index function on the given server. This is typically called at the end of arebuildIndex()- Parameters:
collection- The collection to optimizeserver- The server to use to optimze the given collection- Throws:
ServiceExceptionIOException
-
optimizeIndex
@Deprecated void optimizeIndex(org.apache.solr.client.solrj.SolrClient server) throws ServiceException, IOException Deprecated.UseoptimizeIndex(String, SolrClient)instead so that the collection that's being used can be customized otherwise the default collection will always be used. Generally useSolrConfiguration#getQueryCollectionName()orSolrConfiguration#getReindexCollectionName()Triggers the Solr optimize index function on the given server. This is typically called at the end of arebuildIndex()- Parameters:
server- The server to use to optimze the default collection- Throws:
ServiceExceptionIOException
-
commit
void commit(String collection, org.apache.solr.client.solrj.SolrClient server) throws 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 commitserver- The server used to commit the specified collection- Throws:
ServiceExceptionIOException
-
commit
@Deprecated void commit(org.apache.solr.client.solrj.SolrClient server) throws ServiceException, IOException Deprecated.Usecommit(String, SolrClient)instead so that the collection that's being used can be customized otherwise the default collection will always be used. Generally useSolrConfiguration#getQueryCollectionName()orSolrConfiguration#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:
ServiceExceptionIOException
-
commit
void commit(String collection, org.apache.solr.client.solrj.SolrClient server, boolean softCommit, boolean waitSearcher, boolean waitFlush) throws 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 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:
ServiceExceptionIOException
-
commit
@Deprecated void commit(org.apache.solr.client.solrj.SolrClient server, boolean softCommit, boolean waitSearcher, boolean waitFlush) throws ServiceException, IOException Deprecated.Usecommit(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 useSolrConfiguration#getQueryCollectionName()orSolrConfiguration#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 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:
ServiceExceptionIOException
-
deleteAllNamespaceDocuments
void deleteAllNamespaceDocuments(String collection, org.apache.solr.client.solrj.SolrClient server) throws ServiceException - Throws:
ServiceException
-
deleteAllNamespaceDocuments
@Deprecated void deleteAllNamespaceDocuments(org.apache.solr.client.solrj.SolrClient server) throws ServiceException Deprecated.UsedeleteAllNamespaceDocuments(String, SolrClient)instead so that the collection that's being used can be customized otherwise the default collection will always be used. Generally useSolrConfiguration#getQueryCollectionName()orSolrConfiguration#getReindexCollectionName()- Throws:
ServiceException
-
deleteAllDocuments
void deleteAllDocuments(String collection, org.apache.solr.client.solrj.SolrClient server) throws ServiceException - Throws:
ServiceException
-
deleteAllDocuments
@Deprecated void deleteAllDocuments(org.apache.solr.client.solrj.SolrClient server) throws ServiceException Deprecated.UsedeleteAllDocuments(String, SolrClient)instead so that the collection that's being used can be customized otherwise the default collection will always be used. Generally useSolrConfiguration#getQueryCollectionName()orSolrConfiguration#getReindexCollectionName()- Throws:
ServiceException
-
logDocuments
Prints out the docs to the trace logger- Parameters:
documents-
-
getAllLocales
- Returns:
- a list of all possible locale prefixes to consider
-
buildDocument
org.apache.solr.common.SolrInputDocument buildDocument(Indexable indexable, List<IndexField> fields, List<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 ServiceException SolrIndexService 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++; } } });NoterebuildIndex()already internally wraps its call using CacheOperation, so it is not necessary to call performCacheOperation for calls to rebuildIndex().- Throws:
ServiceException
-
attachIndexableDocumentFields
void attachIndexableDocumentFields(org.apache.solr.common.SolrInputDocument document, Indexable indexable, List<IndexField> fields, List<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.SolrServerExceptionIOException
-
addDocuments
void addDocuments(Collection<org.apache.solr.common.SolrInputDocument> documents) throws IOException, org.apache.solr.client.solrj.SolrServerException - Throws:
IOExceptionorg.apache.solr.client.solrj.SolrServerException
-
logDeleteQuery
-
useLegacyIndexer
boolean useLegacyIndexer()Indicates 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.- Returns:
-
buildIncrementalIndex(String, List, SolrClient)instead so that the collection that's being used can be customized otherwise the default collection will always be used.