Interface SolrHelperService

All Known Implementing Classes:
SolrHelperServiceImpl

public interface SolrHelperService
Author:
Andre Azzolini (apazzolini)
  • Method Details

    • swapActiveCores

      void swapActiveCores(SolrConfiguration solrConfiguration) throws org.broadleafcommerce.common.exception.ServiceException
      Swaps the primary and reindex cores. If the reindex core is null, we are operating in single core mode. In this scenario, no swap occurs.
      Throws:
      org.broadleafcommerce.common.exception.ServiceException
    • getGlobalFacetTagField

      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. Apart from being non-empty, the actual value does not matter.
      Returns:
      the non-empty global facet tag field
    • getPropertyNameForIndexField

      String getPropertyNameForIndexField(IndexField field, FieldType fieldType, String prefix)
      Returns the property name for the given field, field type, and prefix
      Parameters:
      field -
      fieldType -
      prefix -
      Returns:
      the property name for the field and fieldtype
    • getPropertyNameForIndexField

      String getPropertyNameForIndexField(IndexField field, FieldType fieldType)
      Returns 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
      Parameters:
      field -
      fieldType -
      Returns:
      the property name for the field and fieldtype
    • getSolrDocumentId

      String getSolrDocumentId(org.apache.solr.common.SolrInputDocument document, Indexable indexable)
      Returns:
      the Solr id of this indexable
    • getNamespaceFieldName

      String getNamespaceFieldName()
      Returns:
      the name of the field that keeps track what namespace this document belongs to
    • getIdFieldName

      String getIdFieldName()
      Returns:
      the id field name, with the global prefix as appropriate
    • getIndexableIdFieldName

      String getIndexableIdFieldName()
      Returns:
      the id field name. Usually "productId"
    • getCategoryFieldName

      String getCategoryFieldName()
      Returns:
      the category field name, with the global prefix as appropriate
    • getExplicitCategoryFieldName

      String getExplicitCategoryFieldName()
      Returns:
      the explicit category field name, with the global prefix as appropriate
    • getCatalogFieldName

      String getCatalogFieldName()
      The field that should store which catalog the item is being indexed for
    • getCatalogOverridesFieldName

      String getCatalogOverridesFieldName()

      The field that the list of catalogs that have overridden this document are in. In a multitenant environment this works like so:

      1. MASTER_CATALOG exists in a template site with ID 1 and contains #getProductIdFieldName() == 5
      2. Product ID 5 is indexed in Solr with getCatalogFieldName() == 1
      3. A standard site is created whose default catalog id is 2
      4. Catalog 1 is assigned to the standard site as EDITABLE
      5. 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
      6. Solr then creates a new document with #getProductIdFieldName() == 5
      7. and getCatalogFieldName() == 2 (note that it uses the MASTER_CATALOG product ID and not the cloned id)
      8. Solr looks up the original document for getCatalogFieldName() == 1 and #getProductIdFieldName() == 5 and then adds to the list of getCatalogOverridesFieldName(), id 2.
      9. When querying Solr for a list of products within a catalog, documents whose getCatalogOverridesFieldName() contain the current catalog are filtered out.
    • getSandBoxFieldName

      String getSandBoxFieldName()
      The 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.
    • getSandBoxPriorityFieldName

      String getSandBoxPriorityFieldName()
      Which level of the priority tree the sandbox field is in like approval or user
    • getSandBoxChangeTypeFieldName

      String getSandBoxChangeTypeFieldName()
      Used 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
    • getCategorySortFieldName

      String getCategorySortFieldName(Category category)
      Parameters:
      category -
      Returns:
      the default sort field name for this category
    • getCategorySortFieldName

      String getCategorySortFieldName(Long categoryId)
      Parameters:
      categoryId -
      Returns:
      the default sort field name for this category
    • getLocalePrefix

      String getLocalePrefix()
      Determines 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.
      Returns:
      the global prefix if there is one, "" if there isn't
    • getDefaultLocalePrefix

      String getDefaultLocalePrefix()
      Returns:
      the default locale's prefix
    • getDefaultLocale

      org.broadleafcommerce.common.locale.domain.Locale getDefaultLocale()
      Returns 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.

      Returns:
      the default locale
    • getCategoryId

      Long getCategoryId(Category category)
      In 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.
      Parameters:
      category -
      Returns:
      the category id to use
    • getCategoryId

      Long getCategoryId(Long category)
      In 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.
      Parameters:
      category -
      Returns:
      the category id to use
    • getIndexableId

      Long getIndexableId(Indexable indexable)
      In 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.
      Parameters:
      indexable -
      Returns:
      the sku id to use
    • getPrimaryDocumentType

      String getPrimaryDocumentType()
      Returns:
      the type of the primary indexable document
    • getPropertyValue

      See getPropertyValue(Object, String)
      Parameters:
      object -
      field -
      Returns:
      Throws:
      NoSuchMethodException
      InvocationTargetException
      IllegalAccessException
    • getPropertyValue

      This 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.).

      Parameters:
      object -
      propertyName -
      Returns:
      Throws:
      NoSuchMethodException
      InvocationTargetException
      IllegalAccessException
    • optimizeIndex

      void optimizeIndex(String collection, org.apache.solr.client.solrj.SolrClient server) throws org.broadleafcommerce.common.exception.ServiceException, IOException
      Tells Solr to optimize the index. This is an expensive operation and should be used rarely or never.
      Parameters:
      collection - The collection to operate on
      server - The server to use to do the operation
      Throws:
      org.broadleafcommerce.common.exception.ServiceException
      IOException
    • optimizeIndex

      @Deprecated void optimizeIndex(org.apache.solr.client.solrj.SolrClient server) throws org.broadleafcommerce.common.exception.ServiceException, IOException
      Deprecated.
      Use optimizeIndex(String, SolrClient) instead so that the collection that's being used can be customized otherwise the default collection will always be used. Generally use SolrConfiguration.getQueryCollectionName() or SolrConfiguration.getReindexCollectionName()
      Tells Solr to optimize the index. This is an expensive operation and should be used rarely or never.
      Parameters:
      server - The server to use to do the operation
      Throws:
      org.broadleafcommerce.common.exception.ServiceException
      IOException
    • scrubFacetValue

      String scrubFacetValue(String facetValue)
      Parameters:
      facetValue -
      Returns:
    • sanitizeQuery

      String sanitizeQuery(String query)
      Strips out or replaces certain characters / substrings.
      Parameters:
      query -
      Returns:
    • buildSearchFacetDTOs

      List<SearchFacetDTO> buildSearchFacetDTOs(List<SearchFacet> searchFacets)
      Builds a list of SearchFacetDTOs from a list of SearchFacets.
      Parameters:
      searchFacets -
      Returns:
    • isFacetAvailable

      boolean isFacetAvailable(SearchFacet facet, Map<String,String[]> params)
      Checks to see if the requiredFacets condition for a given facet is met.
      Parameters:
      facet -
      params -
      Returns:
    • getSolrRangeString

      String getSolrRangeString(String fieldName, BigDecimal minValue, BigDecimal maxValue)
      Creates a range filter (e.g. field:[minValue TO maxValue])

      If minValue == null or maxValue == null, they are replaced by an '*' for wildcard functionality.

      Parameters:
      fieldName -
      minValue -
      maxValue -
      Returns:
    • getSolrRangeFunctionString

      String getSolrRangeFunctionString(BigDecimal minValue, BigDecimal maxValue)
      Returns a string representing a call to the frange solr function. it is not inclusive of lower limit, inclusive of upper limit.
      Parameters:
      minValue -
      maxValue -
      Returns:
    • getSolrFieldTag

      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.

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

      Parameters:
      fieldName - Name of the index field
      param - Name of the local param (e.g., key, ex, tag)
      range - SearchFacetRange representing the range for which to create a facet.query.
      Returns:
      the value for a Solr param based on the given tagField and range with the given local param name.
    • setFacetResults

      void setFacetResults(Map<String,SearchFacetDTO> namedFacetMap, org.apache.solr.client.solrj.response.QueryResponse response)
      Builds 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.
      Parameters:
      namedFacetMap -
      response -
    • sortFacetResults

      void sortFacetResults(Map<String,SearchFacetDTO> namedFacetMap)
      Invoked 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.
      Parameters:
      namedFacetMap -
    • attachFacets

      @Deprecated void attachFacets(org.apache.solr.client.solrj.SolrQuery query, Map<String,SearchFacetDTO> namedFacetMap)
      Notifies solr about which facets you want it to determine results and counts for.
      Parameters:
      query -
      namedFacetMap -
    • attachFacets

      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.
      Parameters:
      query -
      namedFacetMap -
      searchCriteria -
    • getSolrTaggedFieldString

      String getSolrTaggedFieldString(String indexField, String tag, SearchFacetRange range)
      Returns 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
      Parameters:
      indexField -
      tag -
      range -
      Returns:
    • getResponseDocuments

      List<org.apache.solr.common.SolrDocument> getResponseDocuments(org.apache.solr.client.solrj.response.QueryResponse response)
      Determines the list of SolrDocuments from the QueryResponse
      Parameters:
      response -
      Returns:
    • attachSortClause

      void attachSortClause(org.apache.solr.client.solrj.SolrQuery query, SearchCriteria searchCriteria, String defaultSort)
      Sets up the sorting criteria. This will support sorting by multiple fields at a time
      Parameters:
      query -
      searchCriteria -
      defaultSort -
    • getSolrFieldKeyMap

      Map<String,String> getSolrFieldKeyMap(SearchCriteria searchCriteria, List<IndexField> fields)
    • getNamedFacetMap

      Map<String,SearchFacetDTO> getNamedFacetMap(List<SearchFacetDTO> facets, SearchCriteria searchCriteria)
      Returns a map of fully qualified solr index field key to the searchFacetDTO object
      Parameters:
      facets -
      searchCriteria -
      Returns:
    • attachActiveFacetFilters

      void attachActiveFacetFilters(org.apache.solr.client.solrj.SolrQuery query, Map<String,SearchFacetDTO> namedFacetMap, SearchCriteria searchCriteria)
      Restricts the query by adding active facet filters.
      Parameters:
      query -
      namedFacetMap -
      searchCriteria -
    • getCurrentProductId

      Long getCurrentProductId(Indexable indexable)
    • getProductForIndexable

      Product getProductForIndexable(Indexable indexable)
    • getTypeFieldName

      String getTypeFieldName()
      Returns the type field name, usually 'type_s'
      Returns:
    • getDocumentType

      String getDocumentType(Indexable indexable)
      Returns the type for the given Indexable. For Product's this is "product".
      Parameters:
      indexable -
      Returns:
    • getSearchableIndexFields

      List<IndexField> getSearchableIndexFields()
    • getCategoryFilterIds

      List<Long> getCategoryFilterIds(Category category, SearchCriteria searchCriteria)