@Service(value="blSolrIndexService") public class SolrIndexServiceImpl extends Object implements SolrIndexService
| Modifier and Type | Field and Description |
|---|---|
static String |
ATTR_MAP |
protected SolrSearchServiceExtensionManager |
extensionManager |
protected FieldDao |
fieldDao |
protected LocaleService |
localeService |
protected int |
pageSize |
protected ProductDao |
productDao |
protected SolrHelperService |
shs |
protected SolrIndexDao |
solrIndexDao |
protected org.springframework.transaction.PlatformTransactionManager |
transactionManager |
| Constructor and Description |
|---|
SolrIndexServiceImpl() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
attachBasicDocumentFields(Product product,
org.apache.solr.common.SolrInputDocument document)
Adds the ID, category, and explicitCategory fields for the product to the document
|
org.apache.solr.common.SolrInputDocument |
buildDocument(Product product,
List<Field> 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.
|
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
|
protected void |
buildIncrementalIndex(int page,
int pageSize) |
void |
buildIncrementalIndex(int page,
int pageSize,
boolean useReindexServer)
The internal method for building indexes.
|
protected String |
convertToMappedProperty(String propertyName,
String listPropertyName,
String mapPropertyName)
Converts a propertyName to one that is able to reference inside a map.
|
protected void |
deleteAllDocuments() |
List<Locale> |
getAllLocales() |
protected int |
getCacheSizeInMemoryApproximation(CatalogStructure structure) |
protected Map<String,Object> |
getPropertyValues(Product product,
Field field,
FieldType fieldType,
List<Locale> locales)
Returns a map of prefix to value for the requested attributes.
|
void |
logDocuments(Collection<org.apache.solr.common.SolrInputDocument> documents)
Prints out the docs to the trace logger
|
void |
optimizeIndex(org.apache.solr.client.solrj.SolrServer server)
Triggers the Solr optimize index function on the given server
|
void |
performCachedOperation(SolrIndexCachedOperation.CacheOperation cacheOperation)
SolrIndexService exposes
SolrIndexService.buildIncrementalIndex(int, int, boolean). |
protected List<Product> |
readAllActiveProducts()
This method to read all active products will be slow if you have a large catalog.
|
protected List<Product> |
readAllActiveProducts(int page,
int pageSize)
This method to read active products utilizes paging to improve performance over
readAllActiveProducts(). |
void |
rebuildIndex()
Rebuilds the current index.
|
void |
restoreState(Object[] pack)
Restores state that was saved prior to indexing that might have been altered.
|
Object[] |
saveState()
Saves some global context that might be altered during indexing.
|
@Value(value="${solr.index.product.pageSize}")
protected int pageSize
protected ProductDao productDao
protected FieldDao fieldDao
protected LocaleService localeService
protected SolrHelperService shs
protected SolrSearchServiceExtensionManager extensionManager
protected org.springframework.transaction.PlatformTransactionManager transactionManager
protected SolrIndexDao solrIndexDao
public static String ATTR_MAP
public void performCachedOperation(SolrIndexCachedOperation.CacheOperation cacheOperation) throws ServiceException
SolrIndexServiceSolrIndexService.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:
{@code
performCachedOperation(new SolrIndexCachedOperation.CacheOperation() {performCachedOperation in interface SolrIndexServicecacheOperation - the block of code to perform using a single cache for best performanceServiceExceptionprotected int getCacheSizeInMemoryApproximation(CatalogStructure structure)
public void rebuildIndex()
throws ServiceException,
IOException
SolrIndexServicerebuildIndex in interface SolrIndexServiceServiceExceptionIOExceptionprotected void deleteAllDocuments()
throws ServiceException
ServiceExceptionprotected void buildIncrementalIndex(int page,
int pageSize)
throws ServiceException
ServiceExceptionpublic void buildIncrementalIndex(int page,
int pageSize,
boolean useReindexServer)
throws ServiceException
SolrIndexServicebuildIncrementalIndex in interface SolrIndexServiceuseReindexServer - - if set to false will index directly on the primary serverServiceExceptionSolrIndexService.restoreState(Object[])protected List<Product> readAllActiveProducts()
protected List<Product> readAllActiveProducts(int page, int pageSize)
readAllActiveProducts().
While not optimal, this will reduce the memory required to load large catalogs.
It could still be improved for specific implementations by only loading fields that will be indexed or by accessing
the database via direct JDBC (instead of Hibernate).public List<Locale> getAllLocales()
getAllLocales in interface SolrIndexServicepublic org.apache.solr.common.SolrInputDocument buildDocument(Product product, List<Field> fields, List<Locale> locales)
SolrIndexServicebuildDocument in interface SolrIndexServiceprotected void attachBasicDocumentFields(Product product, org.apache.solr.common.SolrInputDocument document)
product - document - protected void buildFullCategoryHierarchy(org.apache.solr.common.SolrInputDocument document,
CatalogStructure cache,
Long categoryId,
Set<Long> indexedParents)
document - the solr document for the productcache - the catalog structure cachecategoryId - the current category idprotected Map<String,Object> getPropertyValues(Product product, Field field, FieldType fieldType, List<Locale> locales) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
product - field - fieldType - locales - IllegalAccessExceptionInvocationTargetExceptionNoSuchMethodExceptionprotected String convertToMappedProperty(String propertyName, String listPropertyName, String mapPropertyName)
propertyName - listPropertyName - mapPropertyName - public Object[] saveState()
SolrIndexServicesaveState in interface SolrIndexServicepublic void restoreState(Object[] pack)
SolrIndexServicerestoreState in interface SolrIndexServiceSolrIndexService.saveState()public void optimizeIndex(org.apache.solr.client.solrj.SolrServer server)
throws ServiceException,
IOException
SolrIndexServiceoptimizeIndex in interface SolrIndexServiceServiceExceptionIOExceptionpublic void logDocuments(Collection<org.apache.solr.common.SolrInputDocument> documents)
SolrIndexServicelogDocuments in interface SolrIndexServiceCopyright © 2014. All Rights Reserved.