@Service(value="blSolrHelperService") public class SolrHelperServiceImpl extends Object implements SolrHelperService
| Modifier and Type | Field and Description |
|---|---|
protected static Locale |
defaultLocale |
protected org.springframework.core.env.Environment |
environment |
protected GenericEntityDao |
genericEntityDao |
protected static String |
GLOBAL_FACET_TAG_FIELD |
protected SolrIndexServiceExtensionManager |
indexExtensionManager |
protected IndexFieldDao |
indexFieldDao |
protected boolean |
isSolrConfigured |
protected LocaleService |
localeService |
protected static String |
PREFIX_SEPARATOR |
protected SolrSearchServiceExtensionManager |
searchExtensionManager |
protected SearchFacetDao |
searchFacetDao |
protected static String[] |
specialCharacters |
protected SystemPropertiesService |
systemPropertiesService |
| Constructor and Description |
|---|
SolrHelperServiceImpl() |
| Modifier and Type | Method and Description |
|---|---|
void |
attachActiveFacetFilters(org.apache.solr.client.solrj.SolrQuery query,
Map<String,SearchFacetDTO> namedFacetMap,
SearchCriteria searchCriteria)
Restricts the query by adding active facet filters.
|
void |
attachFacets(org.apache.solr.client.solrj.SolrQuery query,
Map<String,SearchFacetDTO> namedFacetMap)
Deprecated.
|
void |
attachFacets(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.
|
void |
attachSortClause(org.apache.solr.client.solrj.SolrQuery query,
SearchCriteria searchCriteria,
String defaultSort)
Sets up the sorting criteria.
|
List<SearchFacetDTO> |
buildSearchFacetDTOs(List<SearchFacet> searchFacets)
Builds a list of SearchFacetDTOs from a list of SearchFacets.
|
protected String |
buildSolrFacetField(String fieldName,
String param)
Builds a
facet.field Solr param based on the fieldName provided. |
protected String |
buildSolrFacetQuery(String fieldName,
SearchFacetRange range,
Boolean addExParam,
String param)
Builds a
facet.query Solr param based on the range and fieldName provided. |
protected String |
convertPrefixListToString(List<String> prefixList) |
protected void |
copyPropertyToCollection(Collection<Object> collection,
Object o) |
String |
getCatalogFieldName()
The field that should store which catalog the item is being indexed for
|
String |
getCatalogOverridesFieldName()
The field that the list of catalogs that have overridden this document are in.
|
String |
getCategoryFieldName() |
List<Long> |
getCategoryFilterIds(Category category,
SearchCriteria searchCriteria) |
Long |
getCategoryId(Category category)
In certain cases, the category id used for Solr indexing is different than the direct id on the product.
|
Long |
getCategoryId(Long category)
In certain cases, the category id used for Solr indexing is different than the direct id on the product.
|
String |
getCategorySortFieldName(Category category) |
String |
getCategorySortFieldName(Long categoryId) |
Long |
getCurrentProductId(Indexable indexable) |
Locale |
getDefaultLocale()
Returns the default locale.
|
String |
getDefaultLocalePrefix() |
String |
getDocumentType(Indexable indexable)
Returns the type for the given Indexable.
|
String |
getExplicitCategoryFieldName() |
String |
getGlobalFacetTagField()
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.
|
String |
getIdFieldName() |
Long |
getIndexableId(Indexable indexable)
In certain cases, the sku id used for Solr indexing is different than the direct id on the sku.
|
String |
getIndexableIdFieldName() |
String |
getLocalePrefix()
Determines if there is a locale prefix that needs to be applied to the given field for this particular request.
|
Map<String,SearchFacetDTO> |
getNamedFacetMap(List<SearchFacetDTO> facets,
SearchCriteria searchCriteria)
Returns a map of fully qualified solr index field key to the searchFacetDTO object
|
String |
getNamespaceFieldName() |
String |
getPrimaryDocumentType() |
Product |
getProductForIndexable(Indexable indexable) |
String |
getPropertyNameForIndexField(IndexField field,
FieldType searchableFieldType)
Returns the property name for the given field and field type.
|
String |
getPropertyNameForIndexField(IndexField field,
FieldType fieldType,
String prefix)
Returns the property name for the given field, field type, and prefix
|
Object |
getPropertyValue(Object object,
Field field)
See getPropertyValue(Object, String)
|
Object |
getPropertyValue(Object object,
String propertyName)
This method is meant to behave in a similar way to Apache's PropertyUtils.getProperty(Object, String).
|
protected Object |
getPropertyValueInternal(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 QueryResponse
|
String |
getSandBoxChangeTypeFieldName()
Used for DELETE documents that are extra documents created in a sandbox when an item is deleted.
|
String |
getSandBoxFieldName()
The field that stores which sandbox the document is active for.
|
String |
getSandBoxPriorityFieldName()
Which level of the priority tree the sandbox field is in like approval or user
|
List<IndexField> |
getSearchableIndexFields() |
String |
getSolrDocumentId(org.apache.solr.common.SolrInputDocument document,
Indexable indexable) |
Map<String,String> |
getSolrFieldKeyMap(SearchCriteria searchCriteria,
List<IndexField> fields) |
String |
getSolrFieldTag(String fieldName,
String param,
SearchFacetRange range)
Builds the value for a Solr param based on the given
fieldName and range with the given local
param name. |
String |
getSolrRangeFunctionString(BigDecimal minValue,
BigDecimal maxValue)
Returns a string representing a call to the frange solr function.
|
String |
getSolrRangeString(String fieldName,
BigDecimal minValue,
BigDecimal maxValue)
Creates a range filter (e.g.
|
String |
getSolrTaggedFieldString(String indexField,
String tag,
SearchFacetRange range)
Returns a fully composed solr field string.
|
protected List<String> |
getSortableFieldTypes() |
protected org.apache.solr.client.solrj.SolrQuery.ORDER |
getSortOrder(String[] sortFieldsSegments,
String sortQuery) |
String |
getTypeFieldName()
Returns the type field name, usually 'type_s'
|
boolean |
isFacetAvailable(SearchFacet facet,
Map<String,String[]> params)
Checks to see if the requiredFacets condition for a given facet is met.
|
void |
optimizeIndex(org.apache.solr.client.solrj.SolrClient server)
Tells Solr to optimize the index.
|
void |
optimizeIndex(String collection,
org.apache.solr.client.solrj.SolrClient server)
Tells Solr to optimize the index.
|
String |
sanitizeQuery(String query)
Strips out or replaces certain characters / substrings.
|
String |
scrubFacetValue(String facetValue) |
void |
setFacetResults(Map<String,SearchFacetDTO> namedFacetMap,
org.apache.solr.client.solrj.response.QueryResponse response)
Builds out the DTOs for facet results from the search.
|
void |
sortFacetResults(Map<String,SearchFacetDTO> namedFacetMap)
Invoked to sort the facet results.
|
void |
swapActiveCores(SolrConfiguration solrConfiguration)
This should only ever be called when using the Solr reindex service to do a full reindex.
|
protected static final String GLOBAL_FACET_TAG_FIELD
protected static final String[] specialCharacters
protected static final String PREFIX_SEPARATOR
protected static Locale defaultLocale
protected SystemPropertiesService systemPropertiesService
protected LocaleService localeService
protected SolrSearchServiceExtensionManager searchExtensionManager
protected SolrIndexServiceExtensionManager indexExtensionManager
protected SearchFacetDao searchFacetDao
protected IndexFieldDao indexFieldDao
@Value(value="${using.solr.server:true}")
protected boolean isSolrConfigured
protected GenericEntityDao genericEntityDao
@Autowired protected org.springframework.core.env.Environment environment
public void swapActiveCores(SolrConfiguration solrConfiguration) throws ServiceException
swapActiveCores in interface SolrHelperServiceSecurityExceptionNoSuchFieldExceptionIllegalAccessExceptionIllegalArgumentExceptionServiceExceptionpublic String getGlobalFacetTagField()
SolrHelperServicegetGlobalFacetTagField in interface SolrHelperServicepublic String getPropertyNameForIndexField(IndexField field, FieldType fieldType, String prefix)
SolrHelperServicegetPropertyNameForIndexField in interface SolrHelperServicepublic String getPropertyNameForIndexField(IndexField field, FieldType searchableFieldType)
SolrHelperServicegetPropertyNameForIndexField in interface SolrHelperServicepublic Long getCategoryId(Category category)
SolrHelperServicegetCategoryId in interface SolrHelperServicepublic Long getCategoryId(Long category)
SolrHelperServicegetCategoryId in interface SolrHelperServicepublic Long getIndexableId(Indexable indexable)
SolrHelperServicegetIndexableId in interface SolrHelperServicepublic String getPrimaryDocumentType()
getPrimaryDocumentType in interface SolrHelperServicepublic Long getCurrentProductId(Indexable indexable)
getCurrentProductId in interface SolrHelperServicepublic Product getProductForIndexable(Indexable indexable)
getProductForIndexable in interface SolrHelperServicepublic String getTypeFieldName()
SolrHelperServicegetTypeFieldName in interface SolrHelperServicepublic String getDocumentType(Indexable indexable)
SolrHelperServicegetDocumentType in interface SolrHelperServicepublic String getSolrDocumentId(org.apache.solr.common.SolrInputDocument document, Indexable indexable)
getSolrDocumentId in interface SolrHelperServicepublic String getNamespaceFieldName()
getNamespaceFieldName in interface SolrHelperServicepublic String getIdFieldName()
getIdFieldName in interface SolrHelperServicepublic String getIndexableIdFieldName()
getIndexableIdFieldName in interface SolrHelperServicepublic String getCategoryFieldName()
getCategoryFieldName in interface SolrHelperServicepublic String getExplicitCategoryFieldName()
getExplicitCategoryFieldName in interface SolrHelperServicepublic String getCatalogFieldName()
SolrHelperServicegetCatalogFieldName in interface SolrHelperServicepublic String getCatalogOverridesFieldName()
SolrHelperServiceThe field that the list of catalogs that have overridden this document are in. In a multitenant environment this works like so:
#getProductIdFieldName() == 5SolrHelperService.getCatalogFieldName() == 1#getProductIdFieldName() == 5SolrHelperService.getCatalogFieldName() == 2 (note that it uses the MASTER_CATALOG product ID and not the cloned id)
SolrHelperService.getCatalogFieldName() == 1 and
#getProductIdFieldName() == 5 and then adds to the list of SolrHelperService.getCatalogOverridesFieldName(), id 2.SolrHelperService.getCatalogOverridesFieldName()
contain the current catalog are filtered out.getCatalogOverridesFieldName in interface SolrHelperServicepublic String getSandBoxFieldName()
SolrHelperServicegetSandBoxFieldName in interface SolrHelperServicepublic String getSandBoxPriorityFieldName()
SolrHelperServicegetSandBoxPriorityFieldName in interface SolrHelperServiceSandBoxType}public String getSandBoxChangeTypeFieldName()
SolrHelperServicegetSandBoxChangeTypeFieldName in interface SolrHelperServicepublic String getCategorySortFieldName(Category category)
getCategorySortFieldName in interface SolrHelperServicepublic String getCategorySortFieldName(Long categoryId)
getCategorySortFieldName in interface SolrHelperServicepublic String getLocalePrefix()
SolrHelperServicegetLocalePrefix in interface SolrHelperServicepublic String getDefaultLocalePrefix()
getDefaultLocalePrefix in interface SolrHelperServicepublic Locale getDefaultLocale()
SolrHelperServicegetDefaultLocale in interface SolrHelperServicepublic Object getPropertyValue(Object object, Field field) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException
SolrHelperServicegetPropertyValue in interface SolrHelperServiceNoSuchMethodExceptionInvocationTargetExceptionIllegalAccessExceptionpublic Object getPropertyValue(Object object, String propertyName) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException
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.).
getPropertyValue in interface SolrHelperServiceNoSuchMethodExceptionInvocationTargetExceptionIllegalAccessExceptionpublic void optimizeIndex(org.apache.solr.client.solrj.SolrClient server)
throws ServiceException,
IOException
SolrHelperServiceoptimizeIndex in interface SolrHelperServiceserver - The server to use to do the operationServiceExceptionIOExceptionpublic void optimizeIndex(String collection, org.apache.solr.client.solrj.SolrClient server) throws ServiceException, IOException
SolrHelperServiceoptimizeIndex in interface SolrHelperServicecollection - The collection to operate onserver - The server to use to do the operationServiceExceptionIOExceptionpublic String scrubFacetValue(String facetValue)
scrubFacetValue in interface SolrHelperServicepublic String sanitizeQuery(String query)
SolrHelperServicesanitizeQuery in interface SolrHelperServicepublic List<SearchFacetDTO> buildSearchFacetDTOs(List<SearchFacet> searchFacets)
SolrHelperServicebuildSearchFacetDTOs in interface SolrHelperServicepublic boolean isFacetAvailable(SearchFacet facet, Map<String,String[]> params)
SolrHelperServiceisFacetAvailable in interface SolrHelperServicepublic String getSolrRangeString(String fieldName, BigDecimal minValue, BigDecimal maxValue)
SolrHelperServicegetSolrRangeString in interface SolrHelperServicepublic String getSolrRangeFunctionString(BigDecimal minValue, BigDecimal maxValue)
SolrHelperServicegetSolrRangeFunctionString in interface SolrHelperServicepublic String getSolrFieldTag(String fieldName, String param, SearchFacetRange range)
SolrHelperServicefieldName and range with the given local
param name.
If range == null, then this will produce a value for a facet.field param: {!param=fieldName}.
Else, then this will produce a value for a facet.query param:
{!ex=fieldName param=fieldName[range#minValue:range#maxValue] frange incl=false l=range#minValue u=range#maxValue}.
getSolrFieldTag in interface SolrHelperServicefieldName - Name of the index fieldparam - Name of the local param (e.g., key, ex, tag)range - SearchFacetRange representing the range for which to create a facet.query.tagField and range with the given local
param name.protected String buildSolrFacetField(String fieldName, String param)
facet.field Solr param based on the fieldName provided.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".facet.field Solr param based on the fieldName provided.protected String buildSolrFacetQuery(String fieldName, SearchFacetRange range, Boolean addExParam, String param)
facet.query Solr param based on the range and fieldName provided.
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}.
fieldName - Name of the index field on which to queryrange - SearchFacetRange representing the range for which to create a facet.query.addExParam - Whether to add an exclude filter by tag ("ex") parameter to the query. This assumes
that the filter has a tag matching the fieldName. Defaults to true.param - Optional name of the main param (e.g., tag, key, ex). Defaults to "key".facet.query Solr param based on the range and fieldName provided.public void setFacetResults(Map<String,SearchFacetDTO> namedFacetMap, org.apache.solr.client.solrj.response.QueryResponse response)
SolrHelperServicesetFacetResults in interface SolrHelperServicepublic void sortFacetResults(Map<String,SearchFacetDTO> namedFacetMap)
SolrHelperServicesortFacetResults in interface SolrHelperService@Deprecated public void attachFacets(org.apache.solr.client.solrj.SolrQuery query, Map<String,SearchFacetDTO> namedFacetMap)
SolrHelperServiceattachFacets in interface SolrHelperServicepublic void attachFacets(org.apache.solr.client.solrj.SolrQuery query,
Map<String,SearchFacetDTO> namedFacetMap,
SearchCriteria searchCriteria)
SolrHelperServiceattachFacets in interface SolrHelperServicepublic String getSolrTaggedFieldString(String indexField, String tag, SearchFacetRange range)
SolrHelperServicegetSolrTaggedFieldString in interface SolrHelperServicepublic List<org.apache.solr.common.SolrDocument> getResponseDocuments(org.apache.solr.client.solrj.response.QueryResponse response)
SolrHelperServicegetResponseDocuments in interface SolrHelperServicepublic void attachSortClause(org.apache.solr.client.solrj.SolrQuery query,
SearchCriteria searchCriteria,
String defaultSort)
SolrHelperServiceattachSortClause in interface SolrHelperServiceprotected org.apache.solr.client.solrj.SolrQuery.ORDER getSortOrder(String[] sortFieldsSegments, String sortQuery)
public Map<String,String> getSolrFieldKeyMap(SearchCriteria searchCriteria, List<IndexField> fields)
getSolrFieldKeyMap in interface SolrHelperServicepublic Map<String,SearchFacetDTO> getNamedFacetMap(List<SearchFacetDTO> facets, SearchCriteria searchCriteria)
SolrHelperServicegetNamedFacetMap in interface SolrHelperServicepublic void attachActiveFacetFilters(org.apache.solr.client.solrj.SolrQuery query,
Map<String,SearchFacetDTO> namedFacetMap,
SearchCriteria searchCriteria)
SolrHelperServiceattachActiveFacetFilters in interface SolrHelperServiceprotected Object getPropertyValueInternal(Object object, String[] components, int currentPosition) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException
protected void copyPropertyToCollection(Collection<Object> collection, Object o)
public List<IndexField> getSearchableIndexFields()
getSearchableIndexFields in interface SolrHelperServicepublic List<Long> getCategoryFilterIds(Category category, SearchCriteria searchCriteria)
getCategoryFilterIds in interface SolrHelperServiceCopyright © 2023. All rights reserved.