Class SolrHelperServiceImpl
- All Implemented Interfaces:
SolrHelperService
- Author:
- Andre Azzolini (apazzolini)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static Localeprotected org.springframework.core.env.Environmentprotected GenericEntityDaoprotected static final Stringprotected SolrIndexServiceExtensionManagerprotected IndexFieldDaoprotected booleanprotected LocaleServiceprotected static final Stringprotected SolrSearchServiceExtensionManagerprotected SearchFacetDaoprotected static final String[]protected SystemPropertiesService -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaliasCollectionMap(org.apache.solr.client.solrj.impl.CloudSolrClient client) voidattachActiveFacetFilters(org.apache.solr.client.solrj.SolrQuery query, Map<String, SearchFacetDTO> namedFacetMap, SearchCriteria searchCriteria) Restricts the query by adding active facet filters.voidattachFacets(org.apache.solr.client.solrj.SolrQuery query, Map<String, SearchFacetDTO> namedFacetMap) Deprecated.voidattachFacets(org.apache.solr.client.solrj.SolrQuery query, Map<String, SearchFacetDTO> namedFacetMap, SearchCriteria searchCriteria) Notifies solr about which facets you want it to determine results and counts for.voidattachSortClause(org.apache.solr.client.solrj.SolrQuery query, SearchCriteria searchCriteria, String defaultSort) Sets up the sorting criteria.buildSearchFacetDTOs(List<SearchFacet> searchFacets) Builds a list of SearchFacetDTOs from a list of SearchFacets.protected StringbuildSolrFacetField(String fieldName, String param) Builds afacet.fieldSolr param based on thefieldNameprovided.protected StringbuildSolrFacetQuery(String fieldName, SearchFacetRange range, Boolean addExParam, String param) Builds afacet.querySolr param based on therangeandfieldNameprovided.protected StringconvertPrefixListToString(List<String> prefixList) protected voidcopyPropertyToCollection(Collection<Object> collection, Object o) The field that should store which catalog the item is being indexed forThe field that the list of catalogs that have overridden this document are in.getCategoryFilterIds(Category category, SearchCriteria searchCriteria) getCategoryId(Long category) In certain cases, the category id used for Solr indexing is different than the direct id on the product.getCategoryId(Category category) In certain cases, the category id used for Solr indexing is different than the direct id on the product.getCategorySortFieldName(Long categoryId) getCategorySortFieldName(Category category) getCurrentProductId(Indexable indexable) Returns the default locale.getDocumentType(Indexable indexable) Returns the type for the given Indexable.This property is needed to be non-null to allow filtering by multiple facets at one time and have the results be an AND of the facets.getIndexableId(Indexable indexable) In certain cases, the sku id used for Solr indexing is different than the direct id on the sku.Determines if there is a locale prefix that needs to be applied to the given field for this particular request.getNamedFacetMap(List<SearchFacetDTO> facets, SearchCriteria searchCriteria) Returns a map of fully qualified solr index field key to the searchFacetDTO objectgetProductForIndexable(Indexable indexable) getPropertyNameForIndexField(IndexField field, FieldType searchableFieldType) Returns the property name for the given field and field type.getPropertyNameForIndexField(IndexField field, FieldType fieldType, String prefix) Returns the property name for the given field, field type, and prefixgetPropertyValue(Object object, String propertyName) This method is meant to behave in a similar way to Apache's PropertyUtils.getProperty(Object, String).getPropertyValue(Object object, Field field) See getPropertyValue(Object, String)protected ObjectgetPropertyValueInternal(Object object, String[] components, int currentPosition) List<org.apache.solr.common.SolrDocument>getResponseDocuments(org.apache.solr.client.solrj.response.QueryResponse response) Determines the list of SolrDocuments from the QueryResponseUsed for DELETE documents that are extra documents created in a sandbox when an item is deleted.The field that stores which sandbox the document is active for.Which level of the priority tree the sandbox field is in like approval or usergetSolrDocumentId(org.apache.solr.common.SolrInputDocument document, Indexable indexable) getSolrFieldKeyMap(SearchCriteria searchCriteria, List<IndexField> fields) getSolrFieldTag(String fieldName, String param, SearchFacetRange range) Builds the value for a Solr param based on the givenfieldNameandrangewith the given localparamname.getSolrRangeFunctionString(BigDecimal minValue, BigDecimal maxValue) Returns a string representing a call to the frange solr function.getSolrRangeString(String fieldName, BigDecimal minValue, BigDecimal maxValue) Creates a range filter (e.g.getSolrTaggedFieldString(String indexField, String tag, SearchFacetRange range) Returns a fully composed solr field string.protected org.apache.solr.client.solrj.SolrQuery.ORDERgetSortOrder(String[] sortFieldsSegments, String sortQuery) Returns the type field name, usually 'type_s'booleanisFacetAvailable(SearchFacet facet, Map<String, String[]> params) Checks to see if the requiredFacets condition for a given facet is met.voidoptimizeIndex(String collection, org.apache.solr.client.solrj.SolrClient server) Tells Solr to optimize the index.voidoptimizeIndex(org.apache.solr.client.solrj.SolrClient server) Tells Solr to optimize the index.sanitizeQuery(String query) Strips out or replaces certain characters / substrings.scrubFacetValue(String facetValue) voidsetFacetResults(Map<String, SearchFacetDTO> namedFacetMap, org.apache.solr.client.solrj.response.QueryResponse response) Builds out the DTOs for facet results from the search.voidsortFacetResults(Map<String, SearchFacetDTO> namedFacetMap) Invoked to sort the facet results.voidswapActiveCores(SolrConfiguration solrConfiguration) This should only ever be called when using the Solr reindex service to do a full reindex.
-
Field Details
-
GLOBAL_FACET_TAG_FIELD
- See Also:
-
specialCharacters
-
PREFIX_SEPARATOR
- See Also:
-
defaultLocale
-
systemPropertiesService
-
localeService
-
searchExtensionManager
-
indexExtensionManager
-
searchFacetDao
-
indexFieldDao
-
isSolrConfigured
@Value("${using.solr.server:true}") protected boolean isSolrConfigured -
genericEntityDao
-
environment
@Autowired protected org.springframework.core.env.Environment environment
-
-
Constructor Details
-
SolrHelperServiceImpl
public SolrHelperServiceImpl()
-
-
Method Details
-
swapActiveCores
This should only ever be called when using the Solr reindex service to do a full reindex.- Specified by:
swapActiveCoresin interfaceSolrHelperService- Throws:
SecurityExceptionNoSuchFieldExceptionIllegalAccessExceptionIllegalArgumentExceptionServiceException
-
aliasCollectionMap
protected Map<String,String> aliasCollectionMap(org.apache.solr.client.solrj.impl.CloudSolrClient client) throws org.apache.solr.client.solrj.SolrServerException, IOException - Throws:
org.apache.solr.client.solrj.SolrServerExceptionIOException
-
getGlobalFacetTagField
Description copied from interface:SolrHelperServiceThis property is needed to be non-null to allow filtering by multiple facets at one time and have the results be an AND of the facets. Apart from being non-empty, the actual value does not matter.- Specified by:
getGlobalFacetTagFieldin interfaceSolrHelperService- Returns:
- the non-empty global facet tag field
-
getPropertyNameForIndexField
Description copied from interface:SolrHelperServiceReturns the property name for the given field, field type, and prefix- Specified by:
getPropertyNameForIndexFieldin interfaceSolrHelperService- Returns:
- the property name for the field and fieldtype
-
getPropertyNameForIndexField
Description copied from interface:SolrHelperServiceReturns the property name for the given field and field type. This will apply the global prefix to the field, and it will also apply either the locale prefix or the pricelist prefix, depending on whether or not the field type was set to FieldType.PRICE- Specified by:
getPropertyNameForIndexFieldin interfaceSolrHelperService- Returns:
- the property name for the field and fieldtype
-
convertPrefixListToString
-
getCategoryId
Description copied from interface:SolrHelperServiceIn certain cases, the category id used for Solr indexing is different than the direct id on the product. This method provides a hook to substitute the category id if necessary.- Specified by:
getCategoryIdin interfaceSolrHelperService- Returns:
- the category id to use
-
getCategoryId
Description copied from interface:SolrHelperServiceIn certain cases, the category id used for Solr indexing is different than the direct id on the product. This method provides a hook to substitute the category id if necessary.- Specified by:
getCategoryIdin interfaceSolrHelperService- Returns:
- the category id to use
-
getIndexableId
Description copied from interface:SolrHelperServiceIn certain cases, the sku id used for Solr indexing is different than the direct id on the sku. This method provides a hook to substitute the sku id if necessary.- Specified by:
getIndexableIdin interfaceSolrHelperService- Returns:
- the sku id to use
-
getPrimaryDocumentType
- Specified by:
getPrimaryDocumentTypein interfaceSolrHelperService- Returns:
- the type of the primary indexable document
-
getCurrentProductId
- Specified by:
getCurrentProductIdin interfaceSolrHelperService
-
getProductForIndexable
- Specified by:
getProductForIndexablein interfaceSolrHelperService
-
getTypeFieldName
Description copied from interface:SolrHelperServiceReturns the type field name, usually 'type_s'- Specified by:
getTypeFieldNamein interfaceSolrHelperService- Returns:
-
getDocumentType
Description copied from interface:SolrHelperServiceReturns the type for the given Indexable. For Product's this is "product".- Specified by:
getDocumentTypein interfaceSolrHelperService- Returns:
-
getSolrDocumentId
public String getSolrDocumentId(org.apache.solr.common.SolrInputDocument document, Indexable indexable) - Specified by:
getSolrDocumentIdin interfaceSolrHelperService- Returns:
- the Solr id of this indexable
-
getNamespaceFieldName
- Specified by:
getNamespaceFieldNamein interfaceSolrHelperService- Returns:
- the name of the field that keeps track what namespace this document belongs to
-
getIdFieldName
- Specified by:
getIdFieldNamein interfaceSolrHelperService- Returns:
- the id field name, with the global prefix as appropriate
-
getIndexableIdFieldName
- Specified by:
getIndexableIdFieldNamein interfaceSolrHelperService- Returns:
- the id field name. Usually "productId"
-
getCategoryFieldName
- Specified by:
getCategoryFieldNamein interfaceSolrHelperService- Returns:
- the category field name, with the global prefix as appropriate
-
getExplicitCategoryFieldName
- Specified by:
getExplicitCategoryFieldNamein interfaceSolrHelperService- Returns:
- the explicit category field name, with the global prefix as appropriate
-
getCatalogFieldName
Description copied from interface:SolrHelperServiceThe field that should store which catalog the item is being indexed for- Specified by:
getCatalogFieldNamein interfaceSolrHelperService
-
getCatalogOverridesFieldName
Description copied from interface:SolrHelperServiceThe field that the list of catalogs that have overridden this document are in. In a multitenant environment this works like so:
- MASTER_CATALOG exists in a template site with ID 1 and contains
#getProductIdFieldName()== 5 - Product ID 5 is indexed in Solr with
SolrHelperService.getCatalogFieldName()== 1 - A standard site is created whose default catalog id is 2
- Catalog 1 is assigned to the standard site as EDITABLE
- Because the standard site can edit the catalog, edits actually create a clone of the original catalog product with the changed fields. This new product that is created in the database via this process has an id of 100
- Solr then creates a new document with
#getProductIdFieldName()== 5
and - Solr looks up the original document for
SolrHelperService.getCatalogFieldName()== 1 and#getProductIdFieldName()== 5 and then adds to the list ofSolrHelperService.getCatalogOverridesFieldName(), id 2. - When querying Solr for a list of products within a catalog, documents whose
SolrHelperService.getCatalogOverridesFieldName()contain the current catalog are filtered out.
SolrHelperService.getCatalogFieldName()== 2 (note that it uses the MASTER_CATALOG product ID and not the cloned id)- Specified by:
getCatalogOverridesFieldNamein interfaceSolrHelperService
- MASTER_CATALOG exists in a template site with ID 1 and contains
-
getSandBoxFieldName
Description copied from interface:SolrHelperServiceThe field that stores which sandbox the document is active for. Whenever a change is made to a new Solr document is created with all of the changed field values and this field set to the sandbox the change is in so that searches work when previewing but are filtered out in production.- Specified by:
getSandBoxFieldNamein interfaceSolrHelperService
-
getSandBoxPriorityFieldName
Description copied from interface:SolrHelperServiceWhich level of the priority tree the sandbox field is in like approval or user- Specified by:
getSandBoxPriorityFieldNamein interfaceSolrHelperService
-
getSandBoxChangeTypeFieldName
Description copied from interface:SolrHelperServiceUsed for DELETE documents that are extra documents created in a sandbox when an item is deleted. These are eventually cleaned up when deployed to production- Specified by:
getSandBoxChangeTypeFieldNamein interfaceSolrHelperService
-
getCategorySortFieldName
- Specified by:
getCategorySortFieldNamein interfaceSolrHelperService- Returns:
- the default sort field name for this category
-
getCategorySortFieldName
- Specified by:
getCategorySortFieldNamein interfaceSolrHelperService- Returns:
- the default sort field name for this category
-
getLocalePrefix
Description copied from interface:SolrHelperServiceDetermines if there is a locale prefix that needs to be applied to the given field for this particular request. By default, a locale prefix is not applicable for category, explicitCategory, or fields that have type Price. Also, it is not applicable for non-translatable fields- Note: This method should NOT return null. There must be a default locale configured.
- Specified by:
getLocalePrefixin interfaceSolrHelperService- Returns:
- the global prefix if there is one, "" if there isn't
-
getDefaultLocalePrefix
- Specified by:
getDefaultLocalePrefixin interfaceSolrHelperService- Returns:
- the default locale's prefix
-
getDefaultLocale
Description copied from interface:SolrHelperServiceReturns the default locale. Will cache the result for subsequent use.Note: There is no currently configured cache invalidation strategy for the the default locale. Override this method to provide for one if you need it.
- Specified by:
getDefaultLocalein interfaceSolrHelperService- Returns:
- the default locale
-
getPropertyValue
public Object getPropertyValue(Object object, Field field) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException Description copied from interface:SolrHelperServiceSee getPropertyValue(Object, String)- Specified by:
getPropertyValuein interfaceSolrHelperService- Returns:
- Throws:
NoSuchMethodExceptionInvocationTargetExceptionIllegalAccessException
-
getPropertyValue
public Object getPropertyValue(Object object, String propertyName) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException Description copied from interface:SolrHelperServiceThis method is meant to behave in a similar way to Apache's PropertyUtils.getProperty(Object, String). This is attempting to get the value or values for a property using the property name specified in field.getPropertyName(). The real difference with this method is that it iterates over Collections, Map values, and arrays until it reaches end of the property name. For example, consider a Product and the property name "defaultSku.fees.currency.currencyCode".
The property "fees" is a collection of SkuFee objects on the Sku. If an Product is passed to this method, with a field defining a property name of "defaultSku.fees.currency.currencyCode", this method will return a Collection of Strings. Specifically, it will return a Set of Strings.
The point is, for Solr indexing, it is often desirable to specify all of the values associated with a product for a given Solr field. In this case, you are trying to get all of the unique currency codes associated with the collection of fees associated with the default Sku for the given product.
This works similarly for Maps, Collections, Dates, Strings, Integers, Longs, and other primitives. Note, though, that this will return complex objects as well, if you do not specify the more primitive property that you are trying to access. For example, if you used "defaultSku.fees.currency" as a property name, you would get a collection of BroadleafCurrency objects back. Solr will not be happy if you try to index these.
Note that, for arrays, this method only works with one dimensional arrays.
For Maps, if a key is not specified, this method ignores the key, and iterates over the values collection and treats the values the same way that it treats any other collection. If they key is specified, then this method returns the keyed value rather than all of the values.
So, for example, if you have a product and a property such as "productAttributes(heatRange).value", it will return a single value if there is a ProductAttribute keyed by "heatRange", or null if there is not. If you use the property "productAttributes.value" then is will return a collection of the values associated with each of the values in the productAttributes map.
In this regard it is quite different than PropertyUtils.getMappedProperty(Object, String).
Keep in mind that, since this method returns either a Collection or a single object that is not a Map or Array, you need to make sure that the field can handle such a value. For example, if your field is intended to index a collection of Strings, you need to make sure Solr's definition of this field (or dynamic field) is a multi-valued type according to your Solr schema definition (e.g. _txt or _ss or _is, etc.).
- Specified by:
getPropertyValuein interfaceSolrHelperService- Returns:
- Throws:
NoSuchMethodExceptionInvocationTargetExceptionIllegalAccessException
-
optimizeIndex
public void optimizeIndex(org.apache.solr.client.solrj.SolrClient server) throws ServiceException, IOException Description copied from interface:SolrHelperServiceTells Solr to optimize the index. This is an expensive operation and should be used rarely or never.- Specified by:
optimizeIndexin interfaceSolrHelperService- Parameters:
server- The server to use to do the operation- Throws:
ServiceExceptionIOException
-
optimizeIndex
public void optimizeIndex(String collection, org.apache.solr.client.solrj.SolrClient server) throws ServiceException, IOException Description copied from interface:SolrHelperServiceTells Solr to optimize the index. This is an expensive operation and should be used rarely or never.- Specified by:
optimizeIndexin interfaceSolrHelperService- Parameters:
collection- The collection to operate onserver- The server to use to do the operation- Throws:
ServiceExceptionIOException
-
scrubFacetValue
- Specified by:
scrubFacetValuein interfaceSolrHelperService- Returns:
-
sanitizeQuery
Description copied from interface:SolrHelperServiceStrips out or replaces certain characters / substrings.- Specified by:
sanitizeQueryin interfaceSolrHelperService- Returns:
-
buildSearchFacetDTOs
Description copied from interface:SolrHelperServiceBuilds a list of SearchFacetDTOs from a list of SearchFacets.- Specified by:
buildSearchFacetDTOsin interfaceSolrHelperService- Returns:
-
isFacetAvailable
Description copied from interface:SolrHelperServiceChecks to see if the requiredFacets condition for a given facet is met.- Specified by:
isFacetAvailablein interfaceSolrHelperService- Returns:
-
getSolrRangeString
Description copied from interface:SolrHelperServiceCreates a range filter (e.g. field:[minValue TO maxValue])If minValue == null or maxValue == null, they are replaced by an '*' for wildcard functionality.
- Specified by:
getSolrRangeStringin interfaceSolrHelperService- Returns:
-
getSolrRangeFunctionString
Description copied from interface:SolrHelperServiceReturns a string representing a call to the frange solr function. it is not inclusive of lower limit, inclusive of upper limit.- Specified by:
getSolrRangeFunctionStringin interfaceSolrHelperService- Returns:
-
getSolrFieldTag
Description copied from interface:SolrHelperServiceBuilds the value for a Solr param based on the givenfieldNameandrangewith the given localparamname.If
range == null, then this will produce a value for afacet.fieldparam:{!param=fieldName}. Else, then this will produce a value for afacet.queryparam:{!ex=fieldName param=fieldName[range#minValue:range#maxValue] frange incl=false l=range#minValue u=range#maxValue}.- Specified by:
getSolrFieldTagin interfaceSolrHelperService- Parameters:
fieldName- Name of the index fieldparam- Name of the local param (e.g., key, ex, tag)range-SearchFacetRangerepresenting the range for which to create afacet.query.- Returns:
- the value for a Solr param based on the given
tagFieldandrangewith the given localparamname.
-
buildSolrFacetField
Builds afacet.fieldSolr param based on thefieldNameprovided.- Parameters:
fieldName- Name of the index field (e.g., mgf_s, heatRange_i, price_p)param- Optional name of the param (e.g., tag, key, ex). Defaults to "ex".- Returns:
- a
facet.fieldSolr param based on thefieldNameprovided.
-
buildSolrFacetQuery
protected String buildSolrFacetQuery(String fieldName, SearchFacetRange range, Boolean addExParam, String param) Builds afacet.querySolr param based on therangeandfieldNameprovided.For example, if given the range of $0.00 - $5.00 on the price_p field, the default result would be
{!ex=price_p key=price_p[0.00:5.00] frange incl=false l=0.00 u=5.00}.If
addExParam == false, then this will produce{!key=price_p[0.00:5.00] frange incl=false l=0.00 u=5.00}.- Parameters:
fieldName- Name of the index field on which to queryrange-SearchFacetRangerepresenting the range for which to create afacet.query.addExParam- Whether to add an exclude filter by tag ("ex") parameter to the query. This assumes that the filter has a tag matching thefieldName. Defaults to true.param- Optional name of the main param (e.g., tag, key, ex). Defaults to "key".- Returns:
- a
facet.querySolr param based on therangeandfieldNameprovided.
-
setFacetResults
public void setFacetResults(Map<String, SearchFacetDTO> namedFacetMap, org.apache.solr.client.solrj.response.QueryResponse response) Description copied from interface:SolrHelperServiceBuilds out the DTOs for facet results from the search. This will then be used by the view layer to display which values are available given the current constraints as well as the count of the values.- Specified by:
setFacetResultsin interfaceSolrHelperService
-
sortFacetResults
Description copied from interface:SolrHelperServiceInvoked to sort the facet results. This method will use the natural sorting of the value attribute of the facet (or, if value is null, the minValue of the facet result). Override this method to customize facet sorting for your given needs.- Specified by:
sortFacetResultsin interfaceSolrHelperService
-
attachFacets
@Deprecated public void attachFacets(org.apache.solr.client.solrj.SolrQuery query, Map<String, SearchFacetDTO> namedFacetMap) Deprecated.Description copied from interface:SolrHelperServiceNotifies solr about which facets you want it to determine results and counts for.- Specified by:
attachFacetsin interfaceSolrHelperService
-
attachFacets
public void attachFacets(org.apache.solr.client.solrj.SolrQuery query, Map<String, SearchFacetDTO> namedFacetMap, SearchCriteria searchCriteria) Description copied from interface:SolrHelperServiceNotifies solr about which facets you want it to determine results and counts for.- Specified by:
attachFacetsin interfaceSolrHelperService
-
getSolrTaggedFieldString
Description copied from interface:SolrHelperServiceReturns a fully composed solr field string. Given indexField = a, tag = ex, and a non-null range, would produce the following String: {!tag=a frange incl=false l=minVal u=maxVal}a- Specified by:
getSolrTaggedFieldStringin interfaceSolrHelperService- Returns:
-
getResponseDocuments
public List<org.apache.solr.common.SolrDocument> getResponseDocuments(org.apache.solr.client.solrj.response.QueryResponse response) Description copied from interface:SolrHelperServiceDetermines the list of SolrDocuments from the QueryResponse- Specified by:
getResponseDocumentsin interfaceSolrHelperService- Returns:
-
getSortableFieldTypes
-
attachSortClause
public void attachSortClause(org.apache.solr.client.solrj.SolrQuery query, SearchCriteria searchCriteria, String defaultSort) Description copied from interface:SolrHelperServiceSets up the sorting criteria. This will support sorting by multiple fields at a time- Specified by:
attachSortClausein interfaceSolrHelperService
-
getSortOrder
-
getSolrFieldKeyMap
public Map<String,String> getSolrFieldKeyMap(SearchCriteria searchCriteria, List<IndexField> fields) - Specified by:
getSolrFieldKeyMapin interfaceSolrHelperService
-
getNamedFacetMap
public Map<String,SearchFacetDTO> getNamedFacetMap(List<SearchFacetDTO> facets, SearchCriteria searchCriteria) Description copied from interface:SolrHelperServiceReturns a map of fully qualified solr index field key to the searchFacetDTO object- Specified by:
getNamedFacetMapin interfaceSolrHelperService- Returns:
-
attachActiveFacetFilters
public void attachActiveFacetFilters(org.apache.solr.client.solrj.SolrQuery query, Map<String, SearchFacetDTO> namedFacetMap, SearchCriteria searchCriteria) Description copied from interface:SolrHelperServiceRestricts the query by adding active facet filters.- Specified by:
attachActiveFacetFiltersin interfaceSolrHelperService
-
getPropertyValueInternal
protected Object getPropertyValueInternal(Object object, String[] components, int currentPosition) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException -
copyPropertyToCollection
-
getSearchableIndexFields
- Specified by:
getSearchableIndexFieldsin interfaceSolrHelperService
-
getCategoryFilterIds
- Specified by:
getCategoryFilterIdsin interfaceSolrHelperService
-