org.broadleafcommerce.core.search.service.solr
Class SolrIndexServiceImpl

java.lang.Object
  extended by org.broadleafcommerce.core.search.service.solr.SolrIndexServiceImpl
All Implemented Interfaces:
SolrIndexService

@Service(value="blSolrIndexService")
public class SolrIndexServiceImpl
extends Object
implements SolrIndexService

Responsible for building and rebuilding the Solr index

Author:
Andre Azzolini (apazzolini)

Field Summary
static String ATTR_MAP
           
protected  SolrSearchServiceExtensionManager extensionManager
           
protected  FieldDao fieldDao
           
protected  LocaleService localeService
           
protected  int pageSize
           
protected  ProductDao productDao
           
protected  SolrHelperService shs
           
protected  org.springframework.transaction.PlatformTransactionManager transactionManager
           
 
Constructor Summary
SolrIndexServiceImpl()
           
 
Method Summary
protected  void attachBasicDocumentFields(Product product, org.apache.solr.common.SolrInputDocument document)
          Adds the ID, category, and explicitCategory fields for the product to the document
protected  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 buildIncrementalIndex(int page, int pageSize)
           
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()
           
protected  List<Locale> getAllLocales()
           
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.
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pageSize

@Value(value="${solr.index.product.pageSize}")
protected int pageSize

productDao

protected ProductDao productDao

fieldDao

protected FieldDao fieldDao

localeService

protected LocaleService localeService

shs

protected SolrHelperService shs

extensionManager

protected SolrSearchServiceExtensionManager extensionManager

transactionManager

protected org.springframework.transaction.PlatformTransactionManager transactionManager

ATTR_MAP

public static String ATTR_MAP
Constructor Detail

SolrIndexServiceImpl

public SolrIndexServiceImpl()
Method Detail

rebuildIndex

public void rebuildIndex()
                  throws ServiceException,
                         IOException
Description copied from interface: SolrIndexService
Rebuilds the current index.

Specified by:
rebuildIndex in interface SolrIndexService
Throws:
ServiceException
IOException

deleteAllDocuments

protected void deleteAllDocuments()
                           throws ServiceException
Throws:
ServiceException

buildIncrementalIndex

protected void buildIncrementalIndex(int page,
                                     int pageSize)
                              throws ServiceException
Throws:
ServiceException

readAllActiveProducts

protected List<Product> readAllActiveProducts()
This method to read all active products will be slow if you have a large catalog. In this case, you will want to read the products in a different manner. For example, if you know the fields that will be indexed, you can configure a DAO object to only load those fields. You could also use a JDBC based DAO for even faster access. This default implementation is only suitable for small catalogs.

Returns:
the list of all active products to be used by the index building task

readAllActiveProducts

protected List<Product> readAllActiveProducts(int page,
                                              int pageSize)
This method to read active products utilizes paging to improve performance over 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).

Returns:
the list of all active products to be used by the index building task
Since:
2.2.0

getAllLocales

protected List<Locale> getAllLocales()
Returns:
a list of all possible locale prefixes to consider

buildDocument

protected 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.

Parameters:
product -
fields -
locales -
Returns:
the document

attachBasicDocumentFields

protected void attachBasicDocumentFields(Product product,
                                         org.apache.solr.common.SolrInputDocument document)
Adds the ID, category, and explicitCategory fields for the product to the document

Parameters:
product -
document -

getPropertyValues

protected Map<String,Object> getPropertyValues(Product product,
                                               Field field,
                                               FieldType fieldType,
                                               List<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:
product -
field -
isPriceField -
prefix -
Returns:
the value of the property
Throws:
IllegalAccessException
InvocationTargetException
NoSuchMethodException

convertToMappedProperty

protected String convertToMappedProperty(String propertyName,
                                         String listPropertyName,
                                         String mapPropertyName)
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


Copyright © 2013. All Rights Reserved.